Tensorflow具有计算AUC的功能:tf.metrics.auc()。这是我的一段代码试图计算auc:
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for epoch in range(training_epochs):
sess.run(optimizer, feed_dict = {x : x_train, y : y_train, p_keep_input: 0.8, p_keep_hidden: 0.5})
avg_cost = sess.run(cost, feed_dict = {x : x_train, y : y_train, p_keep_input: 0.8, p_keep_hidden: 0.5})
if epoch % display_step == 0:
training_acc = accuracy.eval({x : x_train, y : y_train, p_keep_input: 1.0, p_keep_hidden: 1.0})
print("Epoch:", '%03d' % (epoch), "Training Accuracy:", '%.5f' % (training_acc), "cost=", "{:.5f}".format(avg_cost))
print("Optimization Done!")
roc_score = tf.metrics.auc(y, pred)
roc_score = tf.convert_to_tensor(roc_score)
print(roc_score.eval({x : x_test, y : y_test, p_keep_input: 1.0, p_keep_hidden: 1.0}))
我得到的错误的任何部分如下。整个错误非常冗长。
FailedPreconditionError (see above for traceback): Attempting to use uninitialized value auc_4/false_positives
[[Node: auc_4/false_positives/read = Identity[T=DT_FLOAT, _class=["loc:@auc_4/false_positives"], _device="/job:localhost/replica:0/task:0/cpu:0"](auc_4/false_positives)]]
我很感激有关如何解决这个问题的任何指示。感谢
答案 0 :(得分:2)
现在可能为时已晚,但如果您还没有找到解决方案,请尝试此更改:
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
_,roc_score = tf.metrics.auc(y, pred)
print(sess.run(roc_score, feed_dict={x : x_test, y : y_test, p_keep_input: 1.0, p_keep_hidden: 1.0}))