问题描述
我尝试遵循tensorflow API 1.4文档来实现我在学习过程中需要的东西.
I try to follow the tensorflow API 1.4 document to achieve what I need in a learning process.
我现在处于这个阶段,可以产生一个预测对象,例如:
I am now at this stage, can produce a predict object for example:
classifier = tf.estimator.DNNClassifier(feature_columns=feature_cols,hidden_units=[10, 20, 10], n_classes=3, model_dir="/tmp/xlz_model")
predict = classifier.predict(input_fn=input_pd_fn_prt (test_f),predict_keys=["class_ids"])
label =tf.constant(test_l.values, tf.int64)
例如,如何在tf.metrics.auc
中使用预测和标签:
how can I use predict and label in tf.metrics.auc
for example:
out, opt = tf.metrics.auc(label, predict)
我尝试了很多不同的选择.没有明确的文档应该如何使用这些tensorflow API.
I have tried so many different options. there are no clear documentation how these tensorflow APIs can be should be used.
推荐答案
该函数返回2个操作:
auc, update_op = tf.metrics.auc(...)
如果运行sess.run(auc)
,您将取回当前的auc值.这是您要报告的值,例如print sess.run([auc, cost], feed_dict={...})
.
If you run sess.run(auc)
you will get back the current auc value. This is the value you want to report on, for example, print sess.run([auc, cost], feed_dict={...})
.
可能需要通过多次调用sess.run
来计算AUC度量.例如,当您要计算AUC的数据集不适合内存时.这就是update_op
的来源.您需要每次都调用它来累积计算auc
所需的值.
The AUC metric may need to be computed over many calls to sess.run
. For example, when the dataset you're computing the AUC for doesn't fit in memory. That's where the update_op
comes in. You need to call it each time to accumulate the values needed to compute auc
.
因此,在测试集评估期间,您可能会遇到以下问题:
So during a test set evaluation, you might have this:
for i in range(num_batches):
sess.run([accuracy, cost, update_op], feed_dict={...})
print("Final (accumulated) AUC value):", sess.run(auc))
当您想重置累积值时(例如,在重新评估测试集之前),应重新初始化局部变量. tf.metrics
软件包明智地将其累加器变量添加到局部变量集合中,该局部变量集合默认不包括权重之类的可训练变量.
When you want to reset the accumulated values (before you re-evaluate your test set, for example) you should re-initialize your local variables. The tf.metrics
package wisely adds its accumulator variables to the local variables collection, which don't include trainable variables such as weights by default.
sess.run(tf.local_variables_initializer()) # Resets AUC accumulator variables
https://www.tensorflow.org/api_docs/python/tf /metrics/auc
这篇关于如何在估算器模型中使用tf.metrics .__预测输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!