1. 前言
机器学习的本质是从一个function set
中挑选一个最优的function
(
f
∗
f^*
f∗又称为model
)来拟合样本(设样本的真实分布为
f
^
\hat{f}
f^)。因此,影响
f
∗
f^*
f∗质量的因素为:
function set
是否包含 f ^ \hat{f} f^;- 从
function set
中挑选的 f ∗ f^* f∗是否能有效的拟合样本;
本文从以上两点分析机器学习中影响model
效果的因素。
2. 实验
找到一个模型判断Pokemon当前CP值与进化之后的CP值直接的关系。
现给定三个function set
:
function set1:
y = w ∗ x c p + b y=w*x_{cp}+b y=w∗xcp+b;function set2:
y = w 1 ∗ x c p + w 2 ∗ x c p 2 + w 3 ∗ x c p 3 + b y=w_{1}*x_{cp}+w_2*x_{cp}^2+w_3*x_{cp}^3+b y=w1∗xcp+w2∗xcp2+w3∗xcp3+b;function set3:
y = w 1 ∗ x c p + w 2 ∗ x c p 2 + w 3 ∗ x c p 3 + w 4 ∗ x c p 4 + w 5 ∗ x c p 5 + b y=w_{1}*x_{cp}+w_2*x_{cp}^2+w_3*x_{cp}^3+w_4*x_{cp}^4+w_5*x_{cp}^5+b y=w1∗xcp+w2∗xcp2+w3∗xcp3+w4∗xcp4+w5∗xcp5+b;
由上可知:
s
e
t
1
⊂
s
e
t
2
⊂
s
e
t
3
set1\sub set2 \sub set3
set1⊂set2⊂set3,即set3
囊括的范围最大,set2
次之,set1
最小。
2.1 Variance
先对三个function set
从样本空间中进行100次随机采样训练,得到的效果图如下所示:
从上图可以看出:function set3
选出的
f
∗
f^*
f∗的离散程度(方差,Variance)最大,function set2
次之,function set1
最小。由此可以得出:模型越复杂,Variance(方差)越大。
2.2 Bias
假设样本的真实分布
f
^
\hat{f}
f^的函数图像如下:
上述三个function set
的均值如下图蓝色线所示:
从上图可以看出:function set3
选出的
f
∗
f^*
f∗均值与
f
^
\hat{f}
f^的偏移程度(偏置,Bias)最小,function set2
次之,function set1
最大。由此可以得出:模型越简单,Bias(偏置)越大。
3. 分析
3.1 Bias VS Variance
有以上实验可知,Model
的效果与Variance
和Bias
有关。
Model
的error
来自与Variance
和Bias
,而Variance
和Bias
又与Model
的复杂程度有关。梳理如下:
Model
越复杂(function set
的范围大),Variance
越大,Bias
越小;Model
越简单(function set
的范围小),Variance
越小,Bias
越大;- 好的
Model
是Variance
与Bias
的平衡;
3.2 Underfitting VS Overfitting
Underfitting(欠拟合)
是指:当Model
在training data set
中无法获得好的效果时,此时Model
有一个Large Bias
。有两种常用的方案可以解决此问题:
- 增加更多的
features(特征)
; - 增大
Model
的复杂程度; - 训练更长的时间;
Overfitting(过拟合)
是指:当Model
在training data set
中有很好的效果,但是在testing data set
中效果不佳,此时Model
有一个Large Variance
。有两种常用方案可以解决此问题:
4. 使用更多的数据进行训练;
5. 正则化;
6. Early Stopping;