2016-01-13 31 views
34

Eseguo un programma python che chiama i metodi sklearn.metrics per calcolare la precisione e il punteggio F1. Ecco l'uscita quando non c'è nessun campione predetto:perché scikitlearn afferma che il punteggio F1 non è ben definito con FN maggiore di 0?

/xxx/py2-scikit-learn/0.15.2-comp6/lib/python2.6/site-packages/sklearn/metr\ 
ics/metrics.py:1771: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. 
    'precision', 'predicted', average, warn_for) 

/xxx/py2-scikit-learn/0.15.2-comp6/lib/python2.6/site-packages/sklearn/metr\ 
ics/metrics.py:1771: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 due to no predicted samples. 
    'precision', 'predicted', average, warn_for) 

Quando non c'è nessun campione predetto, significa che TP + FP è 0, quindi

  • precisione (definito come TP/(TP + FP)) è 0/0, non definito,
  • Il punteggio F1 (definito come 2TP/(2TP + FP + FN)) è 0 se FN non è zero.

Nel mio caso, sklearn.metrics restituisce anche la precisione di 0,8 e richiama come 0. Quindi FN non è zero.

Ma perché scikilearn dice che la F1 non è ben definita?

Qual è la definizione di F1 utilizzata da Scikilearn?

risposta

16

di precisione, Recall, F1-score e Precisione calcolo

- In a given image of Dogs and Cats 

    * Total Dogs - 12 D = 12 
    * Total Cats - 8 C = 8 

- Computer program predicts 

    * Dogs - 8 
    5 are actually Dogs T.P = 5 
    3 are not    F.P = 3  
    * Cats - 12 
    6 are actually Cats T.N = 6 
    6 are not    F.N = 6 

- Calculation 

    * Precision = T.P/(T.P + F.P) => 5/(5 + 3) 
    * Recall = T.P/D   => 5/12 

    * F1 = 2 * (Precision * Recall)/(Precision + Recall) 
    * F1 = 0.5 

    * Accuracy = T.P + T.N/P + N 
    * Accuracy = 0.55 

Wikipedia reference