本文共 3498 字,大约阅读时间需要 11 分钟。
用数值评价指标来估计算法的执行结果 可以看出学习算法的效果。
在自然语言处理中,可用stemming software(词干提取软件)实现;在搜索引擎中搜Porter Stemmer这种软件进行词干提取。但它们都只处理单词的前几个字母。可以使用交叉验证(not error analysis)在使用词干提取和不使用词干提取条件下分别看看其结果。
Need numerical evaluation(e.g.,cross validation error) of algorithm’s performance with and without stemming.
Without stemming:5% error With stemming:3% error ⟹ \implies ⟹ using stemming 对于特定的问题,采用单一规则的数值评价指标——the cross validation error. 注:要在交叉验证集上做。 other examples: 是否区分大小写,e.g. Distinguish upper vs. lower case (Mom/mom):3.2% ⟹ \implies ⟹ 不区分1.形成一个简单算法
2.查看错误,通过误差分析看它出现了什么失误,以此决定之后的优化方法 3.有了算法和数值评价指标后,有助于实验新的想法并验证该想法,决定自己该放弃些什么For skewed class,需采用其它 Evaluation metric。
Case:Cancer classification Model: h θ ( x ) { y = 1 if c a n c e r y = 0 otherwise h_\theta(x)\begin{dcases} y = 1 &\text{if } cancer \\ y = 0 &\text{otherwise} \end{dcases} hθ(x){ y=1y=0if cancerotherwise Evaluation metric:分类误差/分类精确度 测试集只有1%的误差,而0.50%的病人have cancer。function y = predictCancer(x) y = 0; %ignore x!return
利用上面非机器学习的算法,误差只有0.50%
⟹ \Longrightarrow ⟹显然误差降低了,but 并未真正提升分类模型的质量在上述例子中, y = 1 y = 1 y=1 in presence of rare class that we want to detect.
Predictedclass | Actual class | |
---|---|---|
1 | 0 | |
1 | True Positive(真阳性) | False Negative(假阴性) |
0 | False Positive(假阳性) | True Negative(真阴性) |
(Of all patients where we predicted y = 1 y = 1 y=1, what fraction actually has cancer?)
T r u e p o s i t i v e # p r e d i c t e d p o s i t i v e = T P T P + F P \frac{True\enspace positive}{\#predicted\enspace positive}=\frac{TP}{TP+FP} #predictedpositiveTruepositive=TP+FPTP
即:第一格 比上 第一行.(Of all patients that actually have cancer, what fraction did we correctly detect as having cancer?)
T r u e p o s i t i v e # a c t u a l p o s i t i v e = T P T P + F N \frac{True\enspace positive}{\#actual\enspace positive}=\frac{TP}{TP+FN} #actualpositiveTruepositive=TP+FNTP
即:第一格 比上 第一列.function y = predictCancer(x) y = 0; %ignore x!return
若采用上述算法, P r e c i s i o n = 0 , R e c a l l = 0 Precision = 0, Recall = 0 Precision=0,Recall=0.
结论:对偏斜类中的rare class,采用 Precision/Recall 作为评估度量值。对于Logistic regression: 0 ≤ h θ ( x ) ≤ 1 0\le h_\theta(x)\le1 0≤hθ(x)≤1
Predict 1 if h θ ( x ) ≥ h_\theta(x)\ge hθ(x)≥ threshold Predict 0 if h θ ( x ) < h_\theta(x) < hθ(x)< threshold Suppose we want to predict y = 0 y=0 y=0(cancer) only if very confident.(“宁可放过一百,不可错杀一个”) ⟶ \longrightarrow ⟶ threshold = 0.7,0.9 ⟶ \longrightarrow ⟶ Higher precision, lower recall. Suppose we want to avoid missing too many cases of cancer(avoid false negatives).(“宁可错杀一百,不可放过一个”) ⟶ \longrightarrow ⟶ threshold = 0.3,0.1 ⟶ \longrightarrow ⟶ Higher recall, lower precision.F 1 S c o r e : 2 P R P + R F_1\; Score : 2 \frac{ PR }{P+R} F1Score:2P+RPR
Precision( P ) | Recall( R ) | Average | F 1 S c o r e F_1\; Score 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.392 |
当 P = 0 o r R = 0 ⟹ F 1 S c o r e = 0 P=0\enspace or\enspace R=0\Longrightarrow F_1\; Score = 0 P=0orR=0⟹F1Score=0;
当 P = 1 a n d R = 1 ⟹ F 1 S c o r e = 1 P=1\enspace and\enspace R=1\Longrightarrow F_1\; Score = 1 P=1andR=1⟹F1Score=1; e l s e ⟹ F 1 S c o r e else\Longrightarrow F_1\; Score else⟹F1Score介于 0 − 1 0-1 0−1之间对于Algorithm 3,将Predict均判为 y = 1 y=1 y=1,此时R为1,P极小,显然该算法不可用。若将Average作为数值指标,Algorithm 3的值反而比1和2大。
⟹ \Longrightarrow ⟹Average此时不可作为评估度量值。是否将它们看作同一个单词,是否将它们看作相同的特征
转载地址:http://nymzi.baihongyu.com/