机器学习基础 - [第一章:单变量线性回归](5)梯度下降算法(参数学习方法)

由上一篇文章我们知道,当 J ( θ 0 , θ 1 ) J(\theta_{0},\theta_{1}) J(θ0,θ1)最小时,参数 ( θ 0 , θ 1 ) (\theta_{0},\theta_{1}) (θ0,θ1)所构成的假设函数 h θ = θ 0 + θ 1 x h_{\theta}=\theta_{0}+\theta_{1}x hθ=θ0+θ1x最能够拟合样本数据.

我们以 θ 0 \theta_{0} θ0为x轴, θ 1 \theta_{1} θ1为y轴,代价函数为Z轴画出 θ 0 \theta_{0} θ0 θ 1 \theta_{1} θ1取不同值的图像:
在这里插入图片描述
We will know that we have succeeded when our cost function is at the very bottom of the pits in our graph, i.e. when its value is the minimum. The red arrows show the minimum points in the graph.

The way we do this is by taking the derivative (the tangential line to a function) of our cost function. The slope of the tangent is the derivative at that point and it will give us a direction to move towards. We make steps down the cost function in the direction with the steepest descent. The size of each step is determined by the parameter α, which is called the learning rate.

For example, the distance between each ‘star’ in the graph above represents a step determined by our parameter α. A smaller α would result in a smaller step and a larger α results in a larger step. The direction in which the step is taken is determined by the partial derivative of J ( θ 0 , θ 1 ) J(\theta_0,\theta_1) J(θ0,θ1),Depending on where one starts on the graph, one could end up at different points. The image above shows us two different starting points that end up in two different places.

The gradient descent algorithm is:
θ j : = θ j − α ∗ ∂ J ( θ 0 , θ 1 ) ∂ θ j \theta_j:=\theta_j-\alpha*\frac{\partial{J(\theta_0,\theta_1)}}{\partial{\theta_j}} θj:=θjαθjJ(θ0,θ1)

repeat until convergence:
where

j=0,1 represents the feature index number.

At each iteration j, one should simultaneously update the parameters θ 1 , θ 2 , . . . , θ n \theta_1, \theta_2,...,\theta_n θ1,θ2,...,θn
Updating a specific parameter prior to calculating another one on the j ( t h ) j^{(th)} j(th) iteration would yield to a wrong implementation.
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Albert_YuHan

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值