【发布时间】:2018-01-27 14:52:34
【问题描述】:
我在使用 tensorflow 库中的 AUC 时遇到问题。我每批训练我的模型(卷积神经网络)(我不使用验证集),并且在每个时期之后,我使用独立的测试集来获得我的评估。问题在于 AUC 评估。
在每批中,我计算训练集的 AUC/Accuracy/Loss/Precision/Recall/F1_score,然后汇总这些分数的平均值。当我尝试对测试集做同样的事情时,我再次计算出相同的分数。我注意到除 AUC 之外的所有分数都有不同的值。我认为增加测试的损失函数和增加 AUC 是不正确的。问题是测试的 AUC 与训练的 AUC 几乎相同(尽管它们的准确率、损失误差完全不同)。
with tf.name_scope("output"):
W = tf.Variable(tf.truncated_normal([num_filters_total, num_classes], stddev=0.1), name="W")
b = tf.Variable(tf.constant(0.1, shape=[num_classes]), name="b")
scores = tf.nn.xw_plus_b(h_drop, W, b, name="scores")
predictions = tf.argmax(scores, 1, name="predictions")
l2_loss += tf.nn.l2_loss(W, name="l2_loss")
l2_loss += tf.nn.l2_loss(b, name="l2_loss")
tf.summary.histogram("l2", l2_loss)
tf.summary.histogram("weigths", W)
tf.summary.histogram("biases", b)
with tf.name_scope("auc_score"):
# labelOut = tf.argmax(y_place_holder, 1)
probability = tf.nn.softmax(scores)
# auc_scoreTemp = streaming_auc(y_place_holder, probability, curve="PR")
auc_scoreTemp = tf.metrics.auc(y_place_holder, probability, curve="PR")
auc_score = tf.reduce_mean(tf.cast(auc_scoreTemp, tf.float32), name="auc_score")
tf.summary.scalar("auc_score", auc_score)
with tf.name_scope("accuracy"):
labelOut = tf.argmax(y_place_holder, 1)
correct_prediction = tf.equal(predictions, tf.argmax(y_place_holder, 1), name="correct_prediction")
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32), name="accuracy")
tf.summary.scalar("accuracy", accuracy)
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
for batch in batches:
x_batch, y_batch = list(zip(*batch))
_, accuracy_train, auc_training, loss_train, prec_batch, recall_batch, f1_batch \
= sess.run([train_step, accuracy, auc_score, cross_entropy, precision_mini_batch,
recall_mini_batch, f1_score_min_batch], feed_dict={x_place_holder: x_batch,
y_place_holder: y_batch,
emb_place_holder: vocab_inv_emb_dset,
dropout_keep_prob: dropout_rate})
...
for test_batch in test_batches:
auc_test = None
x_test_batch, y_test_batch = list(zip(*test_batch))
accuracy_test, loss_test, auc_test = sess.run([accuracy, cross_entropy, auc_score],
feed_dict={x_place_holder: x_test_batch,
y_place_holder: y_test_batch,
emb_place_holder: vocab_inv_emb_dset_val,
dropout_keep_prob: 1.0})
我还尝试使用始终返回 1 的 streaming_auc。
编辑
在每个 epoch 结束时,我通过运行来重置局部变量:
sess.run(tf.local_variables_initializer())
但第一批输出的结果非常糟糕。在第一批之后,我从测试集中得到了与训练结果不接近的正常结果。我不知道这是否是正确的方法,但这样的结果似乎更真实。
【问题讨论】:
标签: tensorflow evaluation auc