App下載

python 如何把classification_report輸出到csv文件

流蘇書包 2021-08-17 15:19:48 瀏覽數(shù) (2894)
反饋

在機(jī)器學(xué)習(xí)的模型訓(xùn)練中,我們的統(tǒng)計結(jié)果最后是以classification_report的文本報告來展現(xiàn)的。我們要進(jìn)行數(shù)據(jù)的收集的話,最好的方式是將其輸出到csv文件中,小編在這里分享一個簡潔的方式:

我的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)

是不是很簡單,下面是我導(dǎo)出來的一個結(jié)果:

補(bǔ)充: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 加權(quán)平均算出來的,如0.59 = (431*0.46+569*0.69)/ 1000

以上就是python 如何把classification_report輸出到csv文件的全部內(nèi)容,希望能給大家一個參考,也希望大家多多支持W3Cschool。


0 人點贊