当前位置 博文首页 > python 如何把classification_report输出到csv文件

    python 如何把classification_report输出到csv文件

    作者:农民小飞侠 时间:2021-06-07 18:20

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

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

    补充: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

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持站长博客。

    js
    下一篇:没有了