我试着计算代码,从一个热门的MNIST字母数据中找出准确度分数。我想计算MNIST数据中每个标签的准确度,因为我对精度、召回率和f1分数使用相同的方法。y_true
是数据帧[88800, 26]
。首先,我定义了真正的积极,真正的消极和其他。我的代码是:
for i in y_true:
x=y_true[i]
y=y_pred[i]
for j in range(len(x)):
if (x.values[j] == 1) and (y.values[j] == 1):
print("True Positive", y_pred.columns[i-1])
elif (x.values[j] == 0) and (y.values[j] == 0):
print("True Negative", y_pred.columns[i-1])
elif (x.values[j] == 0) and (y.values[j] == 1):
print("False Positive", y_pred.columns[i-1])
else:
print("False Negative", y_pred.columns[i-1])
输出为:
True Positive 1
True Positive 1
True Negative 1
...
True Negative 26
直到1和26都是标签的行。但是,我意识到,我无法从打印结果中计算每个标签有多少真阳性、真阴性、假阳性和假阴性。我不知道怎么数。能从打印结果中数一数吗?你知道吗
您可以在代码中使用
Counter
:在这之后,
c
将是您想要的输出。你知道吗要打印输出,请使用以下命令:
相关问题 更多 >
编程相关推荐