网络编程
位置:首页>> 网络编程>> Python编程>> python 如何把classification_report输出到csv文件

python 如何把classification_report输出到csv文件

作者:农民小飞侠  发布时间:2023-01-31 21:02:02 

标签:python,classification,report,csv

今天想把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-rbf0.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

来源:https://blog.csdn.net/w5688414/article/details/107458575

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com