阅读说明: 保留原笔记的编号与章节顺序;代码只供查看,没有在本站运行。历史输出不代表当前版本的复现结果。截图/外链图以独立整理的公式、表格、示意或文字替换;纠错与必要补充均作说明。
1. Overfitting
Fundamental causes of overfitting:
- Complicated Model;
- Limited learning data/lables
Two types of error:
- Loss里的error:(手段)
针对训练数据:观测到的训练数据里的y和模型预测值之前的差别 - 预测error(Model Error):(目标)
针对未来的未知数据: 未来的y和模型之间的差别
2. Model Error
2.1 定义
在未来未知数据(test数据)上的error(MSE)
Model error与loss区别:
- Loss function用来构建模型
- model error用来检测模型效果
2.2 Expected error of regression models:
Error的期望组成:
- error: 自己model的y’与真实值y之间差异
- bias:measures how far off in general the models’ predictions are from the correct value
最优model的与真实值y间差异 - variance: is how much the predictions for a given point vary between different realizations of the model
许多的model的y’与最优的model的间的平均差异
2.3 理解bias和variance
偏差与方差: 固定x,考虑多次重新抽训练集得到的预测。其平均预测与真实回归函数的差是偏差;不同训练集预测围绕平均预测的波动是方差。不是把某个训练出来的模型当作不可知的“最优模型”。
- 模型的精确性bias
- model在训练数据有变换下的平均输出结果与真实值相比,得到的平均准确性
- 模型的稳定性variance
- 第一层:模型输出结果的稳定性
- 第二层:“某一次model的数据结果与这个model的平均水平的差距”的平方的期望
2.4 The trade-off between Bias and Variance
容量与误差示意: 容量太小常见训练/验证误差都高;容量增加后训练误差可持续降低,验证误差可能先降后升。两者差距提示泛化问题,但不是对任意数据都成立的定量曲线。
2.5 Bias vs. Variance
| 预测中心 | 波动小 | 波动大 |
|---|---|---|
| 接近真实目标 | 低偏差、低方差 | 低偏差、高方差 |
| 偏离真实目标 | 高偏差、低方差 | 高偏差、高方差 |
| \ | left | right |
|---|---|---|
| up | low bias, low var | low bias, high var |
| down | high bias, low var | high bias, high var |
(Advanced):
估计量的平方误差分解:
展开时交叉项含而消失。回归预测误差再加不可约噪声项。
2.6 How to solve the overfitting problem?
- Increase training data size
- Avoid over-training dataset:
- Filter out features, e.g. feature reduction
Principal component analysis (PCA) - Regularization
Ridge regression, Least absolute shrinkage and selection operator (LASSO)
Logistic Regression-L2, Logistic Regression-L1 - Ensemble Learning
- Filter out features, e.g. feature reduction
3. Regularization
Ridge Regression and LASSO (Least absolute shrinkage and selection operator) are all regularization methods.
3.1 Hyperparameter Optimization
下面L2 penalty公式中就是Hyperparameter。
通过修改的值可以使得在var和bias间达到平衡:随着增大,模型var减少而bias增大
值的确定一般是通过尝试的方法得到:利用含有label data的training data去做cross-validation,来判断最好取值。
3.2 Ridge Regression
Choose model -> calculate loss function -> Numerical Optimization
Ridge Regression improves the loss function definition of Linear Regression by adding an L2 coefficient penalty to the objective.
Regularization is nothing but adding a penalty term to the objective function and controlling the model complexity using that penalty term.
Ridge Regression: L2 penalty in loss function
- Traing stage:
- Testing stage:
Ridge regression就是llinear regression加上平方项的penalty term
3.3 LASSO
LASSO: L1 penalty in loss function
LASSO就是linear regression加上绝对项的penalty term
3.4 Logistic Regression + Regularization
- L1-Regularization
- L2-Regularization
范式Norm p:
Example:
总结:
- L1 regularization和L2 regularization区别:
- L1 tend to provide sparse results,可以做feature selection,对于feature之间有correlation,给出的结果sparse而且不stable,一般用的比较少
- L tend to provide stable solution,对于correlation的情况处理的比较好,但是不能做feature selection
- 各有优劣,选择?很多lib默认用L2,比如Ridge 使用 L2;普通 LinearRegression 不自动加正则项
- 算时,要不要加penalty term?不要