Supervised Learning
给出的输入数据集样本中包含正确答案,根据输入数据预测答案。
Linear Regression
预测一个连续输出
Hypothesis Function:
: Parameters
不同的
会产生不同的假设函数
Cost Function
将线性回归问题转化为求代价函数最小问题
Gradient Descent
使用Gradient Descent最小化各类函数,代价函数为其中之一。
- Randomly Choose
, generally set
as 0.
- Keep Change
to reduce
until end up to minimum.
:= 赋值运算符
:Learning Rate 控制更新参数的幅度
需要同步更新:
将Gradient Descent代入Cost Function
j = 0:
j = 1:
Multivariate Linear Regression
多个feature的线性回归问题,使用Gradient Descent
n: number of features
input (features) of
training example
value of feature
in
training example
hypothesis function:
Paramaters:
Cost function:
Gradient Descent:
Feature Scaling
特征值相差过大时,导致寻找minium耗费时间太长,使用Feature Scaling进行解决。
一般保证,但如果和[-1, 1]相差不大也可以,加快收敛速度
Learning Rate: 太大导致不会每次都下降,太小导致下降缓慢
Mean normalization(均值归一化)
: 训练集中的平均值
: 最大值-最小值
Polymial regression
将多项式中的每一项看作是不同的feature,转化为上面的多feature线性回归
Normal Equation
梯度下降需要经过多次迭代得到最小化的,而Normal Equation只需一次,且不需要feature scaling。
| 1 | 2104 | 5 | 1 | 45 | 460 |
| 1 | 1416 | 3 | 2 | 40 | 232 |
| 1 | 1534 | 3 | 2 | 30 | 315 |
| 1 | 852 | 2 | 1 | 36 | 178 |
| Gradient Descent | Normal Equation |
|---|---|
| Need to choose |
No neede to choose |
| Needs many iterations | Don't need to iterate |
| works well even when n is large | Need to compute |
Classification
Logistic回归
Logistic function == sigmod Function
Cost function
Gradient Descent
与线性回归的梯度下降规则一样,同步更新
MultiClass Classification
One-vs-all
为每一个类都弄一个分类器,输入x,选取输出值最大的分类器
OverFitting
为了符合训练集而选取的feature过多,导致图像扭曲,无法很好的进行预测
- 减少选取的feature
- 正则化(Regularization)
正则化(Regularization)
Linear Gression
Gradient Descent
Noraml Equation
Logisitci Regression
Gradient Descent