Python 在TensorFlow中实现精度度量
我遵循TensorFlow文档中的示例,具体而言,其中指标分配如下:Python 在TensorFlow中实现精度度量,python,tensorflow,Python,Tensorflow,我遵循TensorFlow文档中的示例,具体而言,其中指标分配如下: correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
我想知道:如何实现不同的精度度量。例如地图(平均精度)。假设我有一个函数:
import numpy as np
def accuracyMAP(y_pred, y_real):
def __precision_at_k(r, k):
r = np.asarray(r)[:k] != 0
return np.mean(r)
temp_sorted = y_real[np.argsort(-y_pred)]
till = np.where(temp_sorted==1)
r = temp_sorted[:till[0]+1]
return __precision_at_k(r, len(r))
for batch_xs in x:
y_pred = sess.run(y, feed_dict={x: batch_xs})
acc = accuracyMAP(y_true, y_pred)
一种方法是进行预测并将其传递给平均精度\u scorce
函数:
import numpy as np
def accuracyMAP(y_pred, y_real):
def __precision_at_k(r, k):
r = np.asarray(r)[:k] != 0
return np.mean(r)
temp_sorted = y_real[np.argsort(-y_pred)]
till = np.where(temp_sorted==1)
r = temp_sorted[:till[0]+1]
return __precision_at_k(r, len(r))
for batch_xs in x:
y_pred = sess.run(y, feed_dict={x: batch_xs})
acc = accuracyMAP(y_true, y_pred)
其中,y_真和y_预测都被转换为numpy数组。但是有没有类似于Tensorflow的方法呢?有什么提示吗?如果你的
平均精度评分函数可以对TF张量进行操作,你可以简单地做:acc=mean\u precision\u评分(y\u真,y)
和以后的sess.run(acc,…)
你的意思是评分=精度(y\u真,y);mean\u accurity=tf.reduce\u mean(score)
我得到一个错误,输入'stripdslice'Op的'stripes'的类型int32与参数'begin'的类型int64不匹配。
。还尝试使用tf.cast
,但没有找到传递该命令的方法。您需要显示准确性
函数的代码,以便了解错误的来源。