在评估深度模型时,如何更改阈值?

时间:2018-09-08 15:49:50

标签: python tensorflow deep-learning evaluate

import pandas as pd
import tensorflow as tf
import tempfile``
CSV_COLUMNS = [   ]


train_file = '/home/nick/
test_file = '/home/nick/

def input_fn(data_file, num_epochs, shuffle):
  #"""Input builder function."""
  df_data = pd.read_csv(
      tf.gfile.Open(data_file),
      names=CSV_COLUMNS,
      skipinitialspace=True,
      engine="python",
      skiprows=1)
  # remove NaN elements
  df_data = df_data.dropna(how="any", axis=0) 

  labels = df_data["NPK"].apply(lambda x: "<10" in x).astype(int)

  return tf.estimator.inputs.pandas_input_fn(
      x=df_data,
      y=labels,
      batch_size=100,
      num_epochs=num_epochs,
      shuffle=shuffle,
      num_threads=5)

DA = tf.feature_column.categorical_column_with_vocabulary_list(  )
LO = tf.contrib.layers.sparse_column_with_hash_bucket(    )


deep_columns = [tf.feature_column.indicator_column(DA)  tf.feature_column.indicator_column(PD)

model_dir = tempfile.mkdtemp()
m = tf.contrib.learn.DNNClassifier(
    feature_columns=deep_columns,
    hidden_units=[1024, 512, 256],
    optimizer=tf.train.ProximalAdagradOptimizer(
      learning_rate=0.1,
      l1_regularization_strength=0.001
    ))
# set num_epochs to None to get infinite stream of data.
m.fit(
    input_fn=input_fn(train_file, num_epochs=None, shuffle=True),
    steps=20000)

# set steps to None to run evaluation until all data consumed.
results = m.evaluate(
    input_fn=input_fn(test_file, num_epochs=1, shuffle=False),
    steps=None)
print("model directory = %s" % model_dir)
#in the result we have accuracy, precision auc and other things.       How can I choose them?
for key in sorted(results):
  print("%s: %s" % (key, results[key])) 

我想知道如何在评估深层模型时更改阈值。这是代码,如果运行它,您会看到该值为0.5,我想将其从o更改为1以改善模型 我希望你能帮帮我 谢谢

0 个答案:

没有答案