ISL-Chap2剩余部分笔记

Chap2剩余部分笔记

1.回归问题,如何衡量模型的好坏

对于回归问题,可以使用MSE(mean squared error)来衡量。简单来说,就是把所有估计值实际值的差加起来,再求个均值。
M S E = 1 n i = 1 n ( y i f ^ ( x i ) ) 2 MSE=\frac{1}{n}\sum_{i=1}^n (y_i-\hat{f}(x_i))^2
通常来说,我们要找到在训练集上表现最好,也就是MSE最小的模型。但是,并不能保证,训练集上MSE最小,测试集上MSE也会最小。
MSE
如上图所示,随着模型复杂度的提高,训练集上的MSE在不断减小,但是在测试集上就并非如此(overfitting)。

2.分类问题,如何衡量模型的好坏

上面讨论了回归的情况下使用MSE,但是在分类的情况下怎么办呢?bulingbuling~隆重推出,error rate

the proportion of mistakes that are made if we apply our estimate f ^ \hat{f} to the training observations

1 n i = 1 n I ( y i y i ^ ) \frac{1}{n}\sum_{i=1}^n I(y_i \neq \hat{y_i})
其中 I I 的取值按下面的公式取:
I = { 1 , if  y i y i ^ 0 , if  y i = y i ^ I = \begin{cases} 1, & \text{if $y_i \neq \hat{y_i}$} \\ 0, & \text{if $y_i = \hat{y_i}$} \end{cases}
到了这里那就举俩例子吧:贝叶斯分类器KNN (K-nearest neighbors)

贝叶斯分类器

Bayes Classifier 的分类规则是,把 test observation 分到 Pr 大的那一类里面。
P r ( Y = j X = x 0 ) Pr(Y=j|X=x_0)
其中 x 0 x_0 是predictor vector。
BayesClassifier

The orange shaded region reflects the set of points for which Pr(Y = orange |X) is greater than 50%,
while the blue shaded region indicates the set of points for which the probability is below 50%.
The purple dashed line represents the points where the probability is exactly 50%. This is called the Bayes decision boundary.

那么我们如何衡量贝叶斯分类器的好坏呢。这里引入bayers error rate
1 E ( max j P r ( Y = j X ) ) 1-E(\max_{j}Pr(Y=j|X))
来解释一下这个公式:

  1. P r ( Y = j X ) Pr(Y=j|X) :在 X X (当前这个样本的Attribute向量)的情况下,当前这个样本被划分到 j j 类中的概率。
  2. P r ( Y = 1 X ) > P r ( Y = o t h e r s X ) Pr(Y=1|X)>Pr(Y=others|X) ,那么当前这个样本被判断成 “1”类。这时候判断错的概率也就等于,实际上当前这个样本不属于“1”类的概率。
    (eg:返回 P r ( Y = 1 X ) = Pr(Y=1|X)= 98% -> 当前样本被认定为“1”,但是其实有2%的可能,这个判断是错的,即2%的可能这个样本属于其他类。)

KNN

上面那个分类器看起来很厉害,但是实际中我们不可能知道那个条件概率 P r ( Y = j X ) Pr(Y=j|X) 。很多算法都在试图估计这个条件概率,KNN就是其中一个。
P r ( Y = j X = x 0 ) = 1 K i = 1 I ( y i y i ^ ) Pr(Y=j|X=x_0)=\frac{1}{K}\sum_{i=1} I(y_i \neq \hat{y_i})
简单来说KNN的过程如图所示:
KNN
其中K值选什么会有怎样的影响呢?
KNN-K
由图可知,K值的不同会影响算法的灵活性(flexibility),也会影响决策边界(decision boundary)的的形状。

Reference

《An Introduction to Statistical Learning》

若需引用请注明出处。
若有错误欢迎指正、讨论。

猜你喜欢

转载自blog.csdn.net/qq_31584013/article/details/85511593