【发布时间】:2017-11-05 18:05:20
【问题描述】:
我知道机器学习中 Precision 和 Recall 指标之间的区别。一个优化 False Positives,另一个优化 False Negative。在统计学中,它被称为针对 I 类或 II 类错误进行优化。
但是,我对在什么情况下可以获得完全相反的 Precision 和 Recall 感到困惑?比如 Precision =1 和 Recall=0?。
让我重复一下:
precision = true positives / (true positives + false positives)
recall = true positives / (true positives + false negatives)
这是混淆矩阵
predicted
(+) (-)
---------
(+) | TP | FN |
actual ---------
(-) | FP | TN |
---------
现在,如果对于正 (1) 类的分类器,Precision = 1,这意味着没有 FP,并且所有预测标签都是 TP。
那么对于同一个正类,Recall 怎么可能是 0 呢?如果已经预测了一些 TP,实际上根据 Precision,所有预测的都只是 TP,那么对于 Recall,我们的分子非零,那么在什么情况下,对于同一个分类器正类,可以得到 Recall 0?
为了提供一些上下文,我针对二元分类问题运行了一个逻辑回归分类器。我有一些包含 774 个特征的 23K 训练数据。 770 个特征是二元或虚拟变量。
这是我的类标签的分布:
1 20429
0 12559
这是对大约 25 种超参数值组合进行 5 次网格搜索后的混淆矩阵和准确度值。
The mean train scores are [ 0.66883049 0.54314532 0.67008959 0.63187226 0.63100366 0.53165968
0.54131812 0.55507725 0.5578254 0.57663273 0.57247462 0.57230056
0.54402055 0.5762753 0.50925733 0.45781882 0.39366017 0.39037968
0.3919818 0.38878762 0.39784982 0.39506755 0.48238147 0.38932944
0.39801223]
The mean validation scores are [ 0.66445801 0.54107661 0.66878871 0.63184791 0.6305487 0.5291239
0.53899788 0.55324585 0.55822615 0.57784418 0.57269066 0.57312373
0.54536399 0.57593868 0.50790351 0.45727773 0.39318349 0.38906933
0.39214413 0.38924256 0.39794725 0.39461262 0.4827855 0.38811658
0.39812048]
The score on held out data is: 0.6687887055562773
Hyper-Parameters for Best Score : {'alpha': 0.0001, 'l1_ratio': 0.45}
The accuracy of sgd on test data is: 0.37526523188845107
Classification Metrics for sgd :
precision recall f1-score support
0 0.38 1.00 0.55 3712
1 1.00 0.00 0.00 6185
avg / total 0.77 0.38 0.21 9897
【问题讨论】:
-
我不确定我是否理解。如果精度=1,那么只有当FP=0时。并且 TP 不为 0。Recall=0 时,表示 TP=0。这是矛盾的
标签: python machine-learning precision-recall