python 如何把classification_report输出到csv文件

2021-07-01 0 627

今天想把classification_report的统计结果输出到文件中,我这里分享一下一个简洁的方式:

我的pandas版本:

pandas 1.0.3

代码:

from sklearn.metrics import classification_report
report = classification_report(y_test, y_pred, output_dict=True)
df = pd.DataFrame(report).transpose()
df.to_csv(\"result.csv\", index= True)

是不是很简单,下面是我导出来的一个结果:

python 如何把classification_report输出到csv文件

补充:sklearn classification_report 输出说明

svm-rbf 0.606
precision recall f1-score support
0.0 0.56 0.39 0.46 431
1.0 0.62 0.77 0.69 569
avg / total 0.60 0.61 0.59 1000

最后一行是用support 加权平均算出来的,如0.59 = (431*0.46+569*0.69)/ 1000

以上为个人经验,希望能给大家一个参考,也希望大家多多支持自学编程网。

遇见资源网 Python python 如何把classification_report输出到csv文件 http://www.ox520.com/28781.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务