對於癌症檢測的例子來說,y=1代表有癌症(1代表數目比較小的類)
Precision/Recall
Actual | class | ||
1 | 0 | ||
Predicted | 1 | True positive | False Positive |
class | 0 | False negative | True negative |
\[\Pr ecision = \frac{{True \bullet positive}}{{predicted \bullet positive}} = \frac{{True \bullet positive}}{{True \bullet positive + Fake \bullet positive}}\]
\[{\mathop{\rm Re}\nolimits} call = \frac{{True \bullet positive}}{{actual \bullet positive}} = \frac{{True \bullet positive}}{{True \bullet positive + Fake \bullet nagative}}\]
如果算法有“High precision”和“High recall”,我們就比較自信的認為這個算法是可以的。
在運用邏輯回歸預測癌症的例子中
邏輯回歸:0≤hθ(x)≤1
預測為1:hθ(x)≥0.5
預測為0:hθ(x)<0.5
假設我們想在有癌症的情況下預測y=1
如何做到在非常自信(非常高的准確率)的情況下給出預測結果?
這時需要適當改變“threshold”
預測為1:hθ(x)≥0.7
預測為0:hθ(x)<0.7
這樣做的結果你就會有“High precision”,但是會有“low recall”
“low recall”也是非常糟糕的情況,這種情況下你很可能會告訴一個有癌症的病人說他沒有。。
這時需要適當改變“threshold”
預測為1:hθ(x)≥0.3
預測為0:hθ(x)<0.3
這樣做的結果你就會有“High recall”,但是會有“low precision”,同樣糟糕。。
可以畫出不同“threshold”情況下的“precision”和“recall”
這樣你可以根據需要選擇“threshold”
如何根據“Precision”和“recall”選擇算法?
現假設有不同算法的“Precision”和“recall”
Precision(P) | Recall(R) | Average | F1Score | |
Algorithm 1 | 0.5 | 0.4 | 0.45 | 0.444 |
Algorithm 2 | 0.7 | 0.1 | 0.4 | 0.175 |
Algorithm 3 | 0.02 | 1.0 | 0.51 | 0.0392 |
一種方法是使用兩者的平均值
\[A{\mathop{\rm var}} age:\frac{{P + R}}{2}\]
這樣做算法3會有比較高的得分,但是這樣不太合理
一種是F1Score
\[{F_1}Score:2\frac{{PR}}{{P + R}}\]
這是大多數人的用法
注意:這里的不同算法也可以是同一個算法取不同“threshold”時的情況。