您的位置:首页技术文章
文章详情页

python 如何把classification_report输出到csv文件

【字号: 日期:2022-06-19 18:39:48浏览:5作者:猪猪

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

我的pandas版本:

pandas 1.0.3

代码:

from sklearn.metrics import classification_reportreport = 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 编程
相关文章: