python 如何把classification_report輸出到csv文件
今天想把classification_report的統(tǒng)計結(jié)果輸出到文件中,我這里分享一下一個簡潔的方式:
我的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)
是不是很簡單,下面是我導出來的一個結(jié)果:

補充: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
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python2與Python3的區(qū)別實例總結(jié)
這篇文章主要介紹了Python2與Python3的區(qū)別,結(jié)合實例形式總結(jié)分析了Python2與Python3打印輸出、編碼、數(shù)值運算、異常處理等使用區(qū)別,需要的朋友可以參考下2019-04-04
python實現(xiàn)與arduino的串口通信的示例代碼
本文主要介紹了python實現(xiàn)與arduino的串口通信的示例代碼, 在Python中,我們可以使用pyserial庫來實現(xiàn)與Arduino的串口通信,下面就來介紹一下如何使用,感興趣的可以了解一下2024-01-01
Python NumPy實現(xiàn)數(shù)組排序與過濾示例分析講解
NumPy是Python的一種開源的數(shù)值計算擴展,它支持大量的維度數(shù)組與矩陣運算,這篇文章主要介紹了使用NumPy實現(xiàn)數(shù)組排序與過濾的方法,需要的朋友們下面隨著小編來一起學習吧2023-05-05
簡單聊聊PyTorch里面的torch.nn.Parameter()
torch.nn.parameter是一個被用作神經(jīng)網(wǎng)絡(luò)模塊參數(shù)的tensor,這是一種tensor的子類,下面這篇文章主要給大家介紹了關(guān)于PyTorch里面的torch.nn.Parameter()的相關(guān)資料,需要的朋友可以參考下2022-02-02

