簡體   English   中英

如何在Tensorflow中獲得精度和召回率而不是准確性

[英]How can i get precision & recall instead of accuracy in Tensorflow

我看到“垃圾郵件預測”將郵件分類為其他人發送的垃圾郵件和火腿。

[源代碼] https://github.com/nfmcclure/tensorflow_cookbook/blob/master/09_Recurrent_Neural_Networks/02_Implementing_RNN_for_Spam_Prediction/02_implementing_rnn.py

程序產生以下值。 (損失,准確性)

Veiw結果截圖

在這段代碼中,結果只是損失,准確性,

我認為准確性沒有意義。 我需要精確度,查全率值(用於F1度量)

但是,由於我的代碼分析無法正常工作,因此我知道Precision和Recall。 但是我不知道如何在此代碼中計算(代碼嵌入)Precision和Recall。

我自己成功了,萬歲!

這是代碼:

actuals = tf.cast(y_output, tf.int64)
predictions = tf.argmax(logits_out, 1)

ones_like_actuals = tf.ones_like(actuals)
zeros_like_actuals = tf.zeros_like(actuals)
ones_like_predictions = tf.ones_like(predictions)
zeros_like_predictions = tf.zeros_like(predictions)

tp_op = tf.reduce_sum(
    tf.cast(
      tf.logical_and(
        tf.equal(actuals, ones_like_actuals), 
        tf.equal(predictions, ones_like_predictions)
      ), 
      "float"
    )
)

tn_op = tf.reduce_sum(
    tf.cast(
      tf.logical_and(
        tf.equal(actuals, zeros_like_actuals), 
        tf.equal(predictions, zeros_like_predictions)
      ), 
      "float"
    )
)

fp_op = tf.reduce_sum(
    tf.cast(
      tf.logical_and(
        tf.equal(actuals, zeros_like_actuals), 
        tf.equal(predictions, ones_like_predictions)
      ), 
      "float"
    )
)

fn_op = tf.reduce_sum(
    tf.cast(
      tf.logical_and(
        tf.equal(actuals, ones_like_actuals), 
        tf.equal(predictions, zeros_like_predictions)
      ), 
      "float"
    )
)

我在github中看到了混淆矩陣開源謝謝@Mistobaan !! https://gist.github.com/Mistobaan/337222ac3acbfc00bdac

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM