【发布时间】:2018-10-25 23:11:54
【问题描述】:
我正在尝试计算代码以从单热 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 的行。但是,我意识到,我无法从打印结果中计算每个标签有多少真阳性、真阴性、假阳性和假阴性。我不知道如何计算它。是否可以从打印结果中计算?
【问题讨论】:
-
创建计数变量并在内部增加 if stmt
-
在循环之前,创建四个变量名为
true_positive、true_negative等,并将它们全部初始化为零。在每个 print 语句之后,增加相应的变量。 -
你为什么不只是例如将标签添加到要打印的 if 语句内的列表中(例如,
print("True Positive")下方的output_list.append("TP"))。然后您就可以轻松统计实例了。 -
我仍然无法获得每个标签和变量的计数。这不是计数实例。