简体   繁体   中英

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

I'm seeing Spam Prediction classifying messages as Spam and Ham made by other person.

[source code] https://github.com/nfmcclure/tensorflow_cookbook/blob/master/09_Recurrent_Neural_Networks/02_Implementing_RNN_for_Spam_Prediction/02_implementing_rnn.py

The program produces the following values. (loss, accuracy)

Veiw Result Screenshot

In this code, the result is only loss, accuracy,

I think Accuracy has no meaning. I need Precision, Recall value (for F1 measure)

However, since the my code analysis is not working properly, I know Precision and Recall. But I do not know how to calculate(code embedding) Precision and Recall in this code.

I succeeded it myself, hurray !!

here is the code:

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"
    )
)

I saw confusion matrix open source in github thank you @Mistobaan !! https://gist.github.com/Mistobaan/337222ac3acbfc00bdac

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM