Gradient Descent and Gradient Boosting
手写gradient descent和gradient boosting...
Last updated
手写gradient descent和gradient boosting...
Last updated
ML里的很多问题都可以简化为求解优化问题,让loss function最小的 。
简单的model中L可以直接求解得到,但是对于参数多的L,求解过程困难。因为实际的loss function多是连续、可导的,那就有了gradient descent求解的思路。
Step 1: Take the derivative (gradient) of the loss function for each parameter in it. Step 2: Pick random values for the parameters. Step 3: Plug the parameter values into the derivatives(gradient) Step 4: Calculate the step sizes, step size = slope*learning_rate Step 5: Calculate the new parameter: new parameter = old parameter-step size Back to Step 3 until Step_Size=small, or reach the maximum number of steps
是tolerance,很小的数值(1e-6), 是learning rate。
use gradient to descent to the lowest point in the loss function (sum of the squared residuals); gradient descent can be very sensitive to the learning rate
基于导数的优化问题(不只是gradient descent)都要求提前做好standardization
从上面的过程可以看出,如果要实现一次gradient descent,需要load进去所有的x。如果我们只load部分的dataset,每次换不同的batch去算derivative,这个时候我们叫它out of core learning 在sklearn就是partial_fit
Bagging: independent classifier并行运算,一群high variance, low bias的model,用一些avg的技巧得到最后的结果(因为low bias,所以大家犯不同的错误取平均后应该得到一个真实值),比如weighted average, majority vote, normal average 最后的结果是reduce variance,variance变成了原来的1/N。
Boosting: sequential classifiers串行运算,可以理解成 精英教育,不停培养同一个model,让这个model的error最小。每一个model都在学习在此之前每一个model的mistake。Boosting的问题在于我们需要设置一个stop time or iteration time,因为它有overfitting的问题。
所以 Boosting 有三个要素:
A loss function to be optimized
A weak learner to make predictions. eg. Tree model
An additive model: 将多个弱学习器累加起来组成强学习器,进而使目标损失函数达到极小。
之所以称为 Gradient,是因为在添加新模型时使用了梯度下降算法来最小化的损失
用exponential loss的gradient boosting
让所有的weight都一样,可以是1/N或者是1
让dependent variable变成Y={-1,1} 因为在后期公式里是看正负号判断data的positive/negative
增加错误部分的weights
我们此前的想法都是given x,predict y。y本身有一个predicted value, 也有一个true value. 现在转变一下想法,我们还有一个叫做residual的参数 , residual of on data i.
已知 ,预测每个 , , 用预测结果改进 .
其实,MSE是 , 而