General Linear Model 3
Last updated
Last updated
先有点废话:
当你有了模型以后,你该如何调整模型,这就是regularization,
最后就是模型的cross validation
那如何保证不overfitting呢,因为这是最需要小心的,那很自然我们就会用到regularization
理解model error 中bias 与variance的关系
知道regularization方法试图解决的问题是什么
了解hyper-parameter的概念,以及优化计算hyperparameter的方法——cross validation
当你太关心一些细节,那反而在未知的情况下表现的不好。就像你考gre花大量时间在一道极难的问题上,会出现什么情况呢?
机器学习的目的是为了构建一个模型,让这个模型尽可能的在未知数据上表现的好。
overfitting的定义:如果模型在训练数据上表现很好,反而在未知的数据表现的不太好,这就出于overfitting(这里是连接training和)
什么情况出现overfitting?
When your model is too complicated, it may get overfitting.
Q2: In classification problems. are our features the more the better?(features多余你的data)
比如说你只有两个人的data,但是你用了一堆的feature,这就像你解方程的时候,未知数多余方程数
Fundamental causes of overfitting:
Complicated Model; Limited learning data.
Loss 里的error:(手段)
针对训练数据:观察training data里面的$y$和模型预测的值之间的差别
预测error(Model Error)
针对未来的未知数据:未来的$y$和模型之间的差别
感想:
同为一样,但是目的不同,前面是为了找parameter,后面是为了看对未知数据的效果;
换句话说,这就是理想和现实的差距
Model error 的定义
定义:是指未来未知的数据(test数据)上的error
一点比较:model error 很像loss,但是
loss function 是用来构造模型;
model error 是用来检查模型效果的
Model的部分(这个是关于你的training data)
Expected error of regression models(bias+variance的推导)
Error的期望组成:(是model 的error)
Bias: measures how far off in general the models predictions are from the correct value
Variance: is how much the predictions for a given point vary between different realization of the model
(不重要)Irreducible error:the part that can not be reduced by optmizing the model
一个例子:
当你数据不同的时候,loss function的parameter就会有些不同,所以bias是平均你的parameter
一个类比(这个是training data???不是bias和variance中的$\hat{f}$和training有关系)
学生的考试能力 = 你的平均水平(与这一次没有关系)+这一次的发挥来说对你多正常
模型的精准性bias:
第一层次的理解:模型输出结果与真实值之间的差距。错误!!!
第二层次的理解:这个model在训练数据有变化下的平均输出结果与真实值相比,得到的平均准确性
模型的稳定性variance:
第一层次的理解:模型输出结果的稳定性
第二层次的理解:’某一次model的数据结果与这次model的平均水平的差距‘的平方的期望
Error due to Variance:
The error due to variance is taken as the variability of a model prediction for a given data point
Again, imagine you can repeat the entire model building process multiple times. The variance is how much the predictions for a given point vary between different realizations of the model.
Q:那你怎么从一个training的bias 和variance去看model本身的bias和variance呢?
Ans:这里的模型空间,会随着模型复杂度变大,很自然,你的variance增大,你的bias减小
重要事情:
要回答overfitting和underfitting可以用上面这个图
第一部分,是指在testing data上的表现?就是上面的图?对的,注意纵坐标是testing error;
第二部分,是symptoms是提到
要回答bias和variance可以用下面这个图(这个是对training data的, 就是上面的表格?对的因为在看你的model的参数,就是参数a和b)
例子:有个点(X,Y)它对应的下面四张图代表了四个模型,请判断他们的bias 和variance什么状态
1. 这是你不同的model,不同的loss的parameter不一样,因为training data 不一样
Increase training data size
avoid over-training your dataset:
Filter out features, e.g. feature reduction
Principal component analysis(PCA)
Regularization
Ridge regression, Least absolute shrinkage and selction operation(LASSO)
Logistic Regression-L2, Logistic Regression-L1
Ensemble Learning
情况:在你的testing data 上出现了overfitting的情况(直接在你的loss function上来治疗你的问题,所以这是在testing上增加的?)
所以我们要对overfitting做点事情
Loss特别小的时候,model error 会很大,因为什么? var 大(相当于之前只和training有关系,但是我们需要和testing建立连接)
可以吗?不行。testing data 不知道,testing var 不知道
Model training process
例子:y=ax+b,a 和b已知 a=0.5, b= 85,相当于能连接training 和test的,间接描述testing的,只有这个parameter的函数了
Ridge Regression improves the loss function definition of Linear Regression by introducing variance into the formula
Regularization is nothing but adding a penalty term to the objective function and controlling the model complexity using that penalty term
Training stage:
Ridge regression 就是linear regression加上平方项的penalty term
画出来像等高线
后来可以推广到logistics, 所以就是一个是L1,另外一个就是L2
Lasso(Least absolute shrinkage and selection operator)
总结:
L1::feature selection regularization
L2:是correlation的情况处理的比较好
model error 不存在training上,mse是用来测试机器好不好,所以不是不用Regularization
L1和L2一般就用在linear 和logistics上现在,不过regulizaration这个概念在其他地方都有
建模分两个部分,
实验室
骨架:选择你的大的框架
肉:就是你里面的parameter,min loss function就是填肉
面对世界
做出来这个机器人到底行不行,
这时候就要regularization(要解决overfitting(low bias/high variance),虽然已经在testing data上了,但是还是要回到training data 里面),所以是骨架,还是肉呢?
用regularization的时候只是在training data里,目的是为了调整parameter
从而当用于testing data 时候,我们就取消这个regularization的这个项对么?
Q:对应logistics
bias has a negative first-order derivative in response to model complexity while variance has a positive slope这个图的注解是这样的
Reference:
http://scott.fortmann-roe.com/docs/BiasVariance.html
https://www.zhihu.com/question/27068705
book: pattern recognition?
1.refer to your publications
Maximum margin classifier
dual problem
换成核估计
表现好或者差的定义=预测值-真实值(差值的平方和),所以就是square error或者是mean squre error
Q1: Is the more complicated the better?
当时:
这样的penalty公式中的 就是hyperparameter:
可以让方差和偏差达到平衡:增大,模型方差(variance)减少,偏差增大(bias)
相当于你在用来控制你的参数和
?
Dual 变形后
And
转换成为
可以由dual 来求