机器学习(吴恩达) 第2章 单变量线性回归(一元线性回归)
2-1 模型描述
- 符号:
m = Numbers of training examples(训练样本的数量)
x’s = “input” variable/features(输入变量/特征)
y’s = “output” variable/“target” variable(输出变量/目标变量)
(x,y) = one training example(一个训练样本)
(x(i),y(i)) = ith training example(第i个训练样本) - 监督学习算法如何工作?
给定训练集,通过学习算法得到假设函数。
2-2 代价函数
-
符号:
Hypothesis: h θ ( x ) = θ 0 + θ 1 x h_\theta(x) = \theta_0 + \theta_1x hθ(x)=θ0+θ1x
θ i ′ s \theta_{i's} θi′s:Parameters(模型参数)
-
代价函数
平方误差代价函数
Cost function: J ( θ 0 , θ 1 ) = 1 2 m ∑ i = 1 m ( h θ ( x ( i ) ) − y ( i ) ) 2 J(\theta_0,\theta_1) = \frac{1}{2m}\displaystyle\sum_{i=1}^{m} (h_\theta(x^{(i)}) - y^{(i)})^2 J(θ0,θ1)=2m1i=1∑m(hθ(x(i))−y(i))2
Goal: m i n i m i z e θ 0 , θ 1 J ( θ 0 , θ 1 ) \mathop{minimize}\limits_{ \theta_0,\theta_1 } J(\theta_0,\theta_1) θ0,θ1minimizeJ(θ0,θ1)
2-3,4 代价函数(一)(二)
右边的每一个点,都代表左边的某一条线。即代价函数中的每一对因变量(模型参数)都对应某一个假设函数。
2-5,6 梯度下降及其知识点总结
- 作用:将代价函数J最小化的算法。
梯度下降找到的是局部最优解。 - 梯度下降算法的定义
其中,
(1) α \alpha α 是学习速率, 代表下山的步子,即控制我们以多大的幅度更新参数 θ j \theta_j θj。
(2) θ 0 \theta_0 θ0 和 θ 1 \theta_1 θ1 需要同时更新。
2-7 线性回归的梯度下降
其中,导数项:
将算好的导数项带入后:
在线性回归中运用梯度下降:
(持续更新中…)