classification_report()是python在机器学习中常用的输出模型评估报告的方法。
classification_report()函数介绍
classification_report()语法如下:classification_report(
y_true,
y_pred,
labels=None,
target_names=None,
sample_weight=None,
digits=2,
output_dict=False,
zero_division=“warn”
)
使用示例
from sklearn.metrics import classification_report
测试集真实数据
y_test = [1, 2, 3, 1, 2, 3, 1, 2, 3]
预测结果
y_predicted = [1, 2, 3, 3, 2, 1, 3, 2, 3]
以这两行数据为例,不难直接看出,
预测中预测了
2次1标签,成功1次,1标签预测的准确率率为0.5
3次2标签,成功3次,2标签预测的准确率为1.0
4次3标签,成功2次,3标签预测的准确率为0.5
print(classification_report(y_test, y_predicted))
也可以加上target_names参数,效果如下:
print(classification_report(y_test, y_predicted, target_names=['a类', 'b类', 'c类', 'd类']))
如图左边显示出了新传入的标签名。