2014-02-25 53 views
2

Scikit分類報告將僅顯示兩位數的精度和召回分數。是否可以讓它在點後面顯示4位數,我的意思是代替0.67顯示0.6783?Scikit分類報告 - 更改顯示結果的格式

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?謝謝!

回答

4

不,不可能用classification_report顯示更多數字。格式字符串是硬編碼的,請參閱here

+0

感謝您的答覆。的確非常有用! – Crista23

+0

最後回答:http://stackoverflow.com/a/39770077/3345375 – jkdev

7

我剛碰到這個老問題。 確實有可能在classification_report中有更多精確點。你只需要通過一個digits參數。

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

documentation

位數:INT 的位數格式化輸出浮點數值

演示:

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