Tim*_*Tim 46 python statistics machine-learning scikit-learn
我运行一个python程序,调用sklearn.metrics计算精度和F1分数的方法.这是没有预测样本时的输出:
/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)
Run Code Online (Sandbox Code Playgroud)
当没有预测样本时,意味着TP + FP为0,所以
在我的情况下,sklearn.metrics也将精度返回到0.8,并记为0.因此FN不为零.
但是为什么scikilearn说F1不明确?
Scikilearn使用F1的定义是什么?
Ibr*_*iev 48
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/metrics/classification.py
F1 = 2*(精度*召回)/(精确+召回)
如你所知,如果预测器根本没有预测正类,则精度= TP /(TP + FP) - 精度为0.
召回= TP /(TP + FN),如果预测变量不预测正类 - TP为0 - 则召回为0.
所以现在你要划分0/0.
Waz*_*azy 19
精确度,召回率,F1分数和准确度计算
- 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
Run Code Online (Sandbox Code Playgroud)
维基百科参考
| 归档时间: |
|
| 查看次数: |
40000 次 |
| 最近记录: |