按照课堂所示范例逐步计算(画出各种表)如下多分类的Micro(微), Macro (宏)& Weighted Averages (加权) F1 Score、Recall、precision,和混淆矩阵(confusion matrix)。并用sklearn编程验证你的手动计算。
手动计算 sklearn编程验证import numpy as np
from sklearn.metrics import precision_score, recall_score, f1_score
Actual = np.array(['cat', 'cat', 'cat', 'cat', 'dog', 'dog', 'dog', 'bird', 'bird'])
Predicted= np.array(['cat', 'cat', 'cat', 'cat', 'dog', 'dog', 'cat', 'dog', 'bird'])
print(recall_score(Actual, Predicted, average = 'micro'))
print(precision_score(Actual, Predicted, average = 'micro'))
print(f1_score(Actual, Predicted, average = 'micro'))
print(recall_score(Actual, Predicted, average = 'macro'))
print(precision_score(Actual, Predicted, average = 'macro'))
print(f1_score(Actual, Predicted, average = 'macro'))
print(recall_score(Actual, Predicted, average = 'weighted'))
print(precision_score(Actual, Predicted, average = 'weighted'))
print(f1_score(Actual, Predicted, average = 'weighted'))
验证结果
结果与心得
macor与weighted在f1_score上存在数据不一致现象(原因尚未找到),其他数据结果一致。
原创不易 转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)