求分类问题的精确率accuracy 采用 tf.reduce_mean tf.cast tf.equal

import tensorflow as tf

A = [1, 3, 4, 5, 6]
B = [1, 3, 4, 3, 2]

correct_prediction = tf.equal(A, B)
with tf.Session() as sess:
    # print(sess.run(tf.equal(A, B)))
    print(sess.run(tf.equal(A, B)))
    print(sess.run(tf.cast(correct_prediction, tf.float32)))
    print(sess.run(tf.reduce_mean(tf.cast(correct_prediction, tf.float32))))

输出

[ True  True  True False False]
[1. 1. 1. 0. 0.]
0.6

你可能感兴趣的:(Tensorflow)