【吴恩达机器学习笔记】第二章:单变量线性回归

单变量线性回归(Univariate linear regression)

介绍

一个数据集也被称为一个训练集

  • 数据集的表示
    m :数据集样本容量
    (x,y) :一个样本,x为输入,y为输出
    x ( i ) x^{(i)} x(i) :第i个样本的输入 , y ( i ) y^{(i)} y(i):第i个样本的输出
  • 学习算法的任务就是根据训练集来输出一个函数,这个函数能够根据input来预测output
    在这里插入图片描述
    定义代价函数(平方误差代价函数:square error cost function )
    J ( θ 0 , θ 1 ) = 1 2 m ∑ i = 1 n ( h θ ( x ( i ) ) − y ( i ) ) 2 J(\theta_0,\theta_1)=\frac{1}{2m}\sum_{i=1}^n(h_\theta(x^{(i)})-y^{(i)})^2 J(θ0,θ1)=2m1i=1n(hθ(x(i))y(i))2
    其中 h θ ( x i ) = θ 0 + θ 1 x ( i ) h_\theta(x^{i})=\theta_0+\theta_1x^{(i)} hθ(xi)=θ0+θ1x(i)
    为我们要求出的预测函数。
    我们要做的事是求出 θ 0 和 θ 1 \theta_0和\theta_1 θ0θ1使得代价函数最小。
  • 梯度下降法( Gradient Descent)
    给出一个函数 J ( θ 0 , θ 1 , . . . , θ n ) J(\theta_0,\theta_1,...,\theta_n) J(θ0,θ1,...,θn)梯度下降法可以求得其取最小值时,参数 θ 0 , θ 1 , . . . θ n \theta_0,\theta_1,...\theta_n θ0,θ1,...θn的值。
    • 过程(此处的梯度下降法为“Batch” Gradient Descent,每一步更新都会遍历整个数据集,还有其他的梯度下降法)
      repeat until convergence {
      θ j : = θ j − α ∂ ∂ θ j J ( θ 0 , θ 1 ) \theta_j := \theta_j-\alpha\frac{\partial}{\partial \theta_j}J(\theta_0,\theta_1) θj:=θjαθjJ(θ0,θ1) ( j = 0   a n d   j = 1 ) (j=0\ and\ j=1) (j=0 and j=1)
      }
      α \alpha α被称为学习率(learning rate),它决定了梯度下降的速度
    • 同时更新
      t e m p 0 : = θ 0 − ∂ ∂ θ 0 J ( θ 0 , θ 1 ) temp0 := \theta_0-\frac{\partial}{\partial \theta_0}J(\theta_0,\theta_1) temp0:=θ0θ0J(θ0,θ1)
      t e m p 1 : = θ 1 − ∂ ∂ θ 1 J ( θ 0 , θ 1 ) temp1 := \theta_1-\frac{\partial}{\partial \theta_1}J(\theta_0,\theta_1) temp1:=θ1θ1J(θ0,θ1)
      θ 0 : = t e m p 0 \theta_0:=temp0 θ0:=temp0
      θ 1 : = t e m p 1 \theta_1:=temp1 θ1:=temp1
    • 梯度下降法单变量时的直观解释
      在这里插入图片描述
    • 学习率 α \alpha α的直观解释
      在这里插入图片描述

线性回归的梯度下降

根据公式,求偏导代入即可
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值