我想弄清楚为什么F1的分数是sklearn的分数。据我所知,其计算方法是:
F1 = 2 * (precision * recall) / (precision + recall)我的代码:
from sklearn.metrics import f1_score, precision_score, recall_score
...
fmeasure1 = f1_score(true_output, predicted_output, average="macro")
fmeasure2 = f1_score(true_output, predicted_output, average="micro")
precision = precision_score(true_output, predicted_output, average="macro")
recall = recall_score(true_output, predicted_output, average="macro")
print 2*(precision*recall)/(precision + recall), fmeasure1, fmeasure2我为我的数据得到的值是:
0.785744255639 0.769527615775 0.984532095901我不明白为什么这三种价值观是不同的。我试着阅读了文档这里,但是我还是很迷茫。
我的数据集是mutli类,本质上是高度不平衡的。这里的哪个值是“正确的”值,并推广说,在平均参数(即无,微观,宏观,权重)中,我应该使用哪些参数?
谢谢,任何见解都是非常有价值的。
发布于 2016-12-22 07:40:23
查看返回值:
Returns:
f1_score : float or array of float, shape = [n_unique_labels]
F1 score of the positive class in binary classification or weighted average of the F1 scores of each class for the multiclass task.每个值都是该特定类的F1评分,因此可以用不同的分数预测每个类。
关于什么是最好的分数。
best value at 1 and worst score at 0.[ \[From documentation\]][1]另外,如果您正在处理高度不平衡的数据集,您应该考虑查看抽样方法,或者在允许的情况下从现有数据中进行简单的子样本。
如果你想要一个平均的预测average='weighted'
sklearn.metrics.f1_score(y_true, y_pred, labels=None, pos_label=1, average='weighted')https://stackoverflow.com/questions/41277915
复制相似问题