【问题标题】:Scikit classification report - change the format of displayed resultsScikit 分类报告 - 更改显示结果的格式
【发布时间】:2014-03-28 03:51:39
【问题描述】:

Scikit 分类报告将仅显示两位数的精度和召回分数。是否有可能让它在点后显示 4 位数字,我的意思是而不是 0.67 来显示 0.6783?

 from sklearn.metrics import classification_report
 print classification_report(testLabels, p, labels=list(set(testLabels)), target_names=['POSITIVE', 'NEGATIVE', 'NEUTRAL'])
                     precision    recall  f1-score   support

         POSITIVE       1.00      0.82      0.90     41887
         NEGATIVE       0.65      0.86      0.74     19989
         NEUTRAL        0.62      0.67      0.64     10578

另外,我应该担心 1.00 的精度分数吗?谢谢!

【问题讨论】:

    标签: python machine-learning scikit-learn classification svm


    【解决方案1】:

    我刚刚遇到了这个老问题。 在classification_report 中确实可以有更多的精度点。你只需要传入一个digits 参数。

    classification_report(y_true, y_pred, target_names=target_names, digits=4)
    

    来自documentation

    数字:整数 格式化输出浮点值的位数

    演示:

    from sklearn.metrics import classification_report
    y_true = [0, 1, 2, 2, 2]
    y_pred = [0, 0, 2, 2, 1]
    target_names = ['class 0', 'class 1', 'class 2']
    
    print(classification_report(y_true, y_pred, target_names=target_names))
    

    输出:

           precision    recall  f1-score   support
    
        class 0       0.50      1.00      0.67         1
        class 1       0.00      0.00      0.00         1
        class 2       1.00      0.67      0.80         3
    
    avg / total       0.70      0.60      0.61         5
    

    4位数字:

    print(classification_report(y_true, y_pred, target_names=target_names, digits=4))
    

    输出:

                 precision    recall  f1-score   support
    
        class 0     0.5000    1.0000    0.6667         1
        class 1     0.0000    0.0000    0.0000         1
        class 2     1.0000    0.6667    0.8000         3
    
    avg / total     0.7000    0.6000    0.6133         5
    

    【讨论】:

      【解决方案2】:

      不,classification_report 不能显示更多数字。格式字符串是硬编码的,见here

      编辑:有更新,请参阅 CentAu 的回答

      【讨论】:

      • 感谢您的回复。确实很有用!
      猜你喜欢
      • 2023-03-03
      • 2022-06-13
      • 2020-02-14
      • 2020-09-19
      • 2015-07-26
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多