使用张量板查找 DNNRegressor 的准确性
Posted
技术标签:
【中文标题】使用张量板查找 DNNRegressor 的准确性【英文标题】:Find accuracy of DNNRegressor with tensorboard 【发布时间】:2018-07-03 00:31:29 【问题描述】:有没有办法在张量板的每次迭代后显示这个 DNNRegression 模型的准确性?我看到的唯一方法是使用“会话”方法,而不是使用 tf.estimator。此外,有没有一种方法可以找到模型的最终精度,而无需手动操作?我尝试了评估方法,但它返回的字典没有“准确”键。
import numpy as np
import tensorflow as tf
import _pickle as cPickle
with open("var_x.txt", "rb") as fp: # Unpickling
var_x = cPickle.load(fp)
with open("var_y.txt", "rb") as fp: # Unpickling
var_y = cPickle.load(fp)
with open("var_x_test.txt", "rb") as fp: # Unpickling
var_x_test = cPickle.load(fp)
with open("var_y_test.txt", "rb") as fp: # Unpickling
var_y_test = cPickle.load(fp)
test_set = tf.contrib.learn.datasets.base.load_csv_with_header(
filename="test.csv",
target_dtype=np.float64,
features_dtype=np.float64)
feature_columns = [tf.feature_column.numeric_column("x", shape=[4])]
estimator = tf.estimator.DNNRegressor(feature_columns=feature_columns, hidden_units=[1024, 512, 256])
# define our data sets
x_train = np.array(var_x)
y_train = np.array(var_y)
x_test = np.array(var_x_test)
y_test = np.array(var_y_test)
input_fn = tf.estimator.inputs.numpy_input_fn(
"x": x_train, y_train, batch_size=4, num_epochs=60, shuffle=True)
# train
estimator.train(input_fn=input_fn, steps=1000)
#TESTING
prediction_input_fn= tf.estimator.inputs.numpy_input_fn(
x ="x":x_test,
num_epochs=1,
shuffle=False
)
predictions = list(estimator.predict(input_fn=prediction_input_fn))
s=0
for i in range(len(predictions)):
print(str(int(abs(round(predictions[i]['predictions'][0]))))+"\n")
if (int(abs(round(predictions[i]['predictions'][0]))) == y_test[i]):
s+=1
print(s)
【问题讨论】:
【参考方案1】:要查看最终准确度,您需要调用estimator.evaluate(..)
,它会返回一个评估矩阵(损失、准确度...)
查看此链接
https://www.tensorflow.org/versions/master/api_docs/python/tf/estimator/DNNRegressor
【讨论】:
以上是关于使用张量板查找 DNNRegressor 的准确性的主要内容,如果未能解决你的问题,请参考以下文章