0
我想繪製tf.contrib.learn.LinearClassifier
我訓練的ROC曲線。ROC曲線tf.contrib.learn.LinearClassifier
ROC曲線示出了作爲鑑別閾值改變TPR和FPR的不同的值,但鑑別閾值始終是0.5。
我看不出告訴LinearClassifier
去改變它,或登錄TPR和FPR針對不同的閾值。
我想繪製tf.contrib.learn.LinearClassifier
我訓練的ROC曲線。ROC曲線tf.contrib.learn.LinearClassifier
ROC曲線示出了作爲鑑別閾值改變TPR和FPR的不同的值,但鑑別閾值始終是0.5。
我看不出告訴LinearClassifier
去改變它,或登錄TPR和FPR針對不同的閾值。
我終於想出瞭如何做到這一點。我需要添加自定義指標,如:
def recall_fn(predictions=None, labels=None, weights=None):
recall = tf.metrics.recall_at_thresholds(labels, predictions[:,1],[0.2,0.5,0.7])
return recall
然後定義我的指標,如:
with tf.variable_scope("metrics"):
validation_metrics = {
"recall":
tf.contrib.learn.MetricSpec(
metric_fn=recall_fn,
prediction_key=tf.contrib.learn.PredictionKey.PROBABILITIES)
}
終於在評估方法調用中使用它們:
results = m.evaluate(input_fn=lambda: chk_batch_input_fn(test_stream),
steps=100, metrics=validation_metrics)
不完全是ROC曲線,但它是我想要的反饋/指標。
使用'predict_proba'並自己進行閾值處理。 –