1. 梯度下降法
当(n geq 1)时:
( heta_j := heta_j - alpha frac{1}{m} sum_{i=1}^m (h_ heta(x^{(i)}) - y^{(i)}) x^{(i)}_j)
例如:
( heta_0 := heta_0 - alpha frac{1}{m} sum_{i=1}^m (h_ heta(x^{(i)}) - y^{(i)}) x^{(i)}_0)
( heta_1 := heta_1 - alpha frac{1}{m} sum_{i=1}^m (h_ heta(x^{(i)}) - y^{(i)}) x^{(i)}_1)
利用偏导数对参数进行迭代更新,参数(vec heta)沿着代价函数(cost function)的梯度下降,逐渐接近代价函数的极值。
2. Logistic Regression
-
定义:
(h_ heta(x)=g( heta^Tx)),
(g(z)=cfrac1{1+e^{-z}})
-
逻辑回归中:
(h_ heta (x) =) (当输入为x时,(y = 1)的)概率
即(h_ heta (x) = P( y=1|x; heta))
且$ P( y=0|x; heta)+P( y=1|x; heta)=1$
-
decision boundary 决策边界
-
logistic regression cost function 逻辑回归代价函数
(J( heta)=frac1msum_{i=1}^mCost(h heta(x^{(i)},y^{(i)})))$Cost(h_ heta(x),y) =
egin{cases}
-log(h_ heta(x)) & ext{if (y=1)}
-log(1-h_ heta(x)) & ext{if (y=0)}
end{cases}$Note: y = 0 or 1 always
-
简化的代价函数和梯度下降法
(Cost(h_ heta(x),y)=-ylog(h_ heta(x)); - ; (1-y)log(1-h_ heta(x)))
(egin{align} J( heta) = & frac1msum_{i=1}^mCost(h_ heta(x),y) \ = & -frac1mleft[sum_{i=1}^my^{(i)}log(h_ heta(x^{(i)})); - ; (1-y^{(i)})log(1-h_ heta(x^{(i)})) ight] end{align})
求得 (min_ heta J( heta))
通过新的x预测:
输出(h_ heta(x)=cfrac1{1+e^{- heta^Tx}})
(线性假设函数:(h_ heta(x)= heta^Tx))
梯度下降法:Repeat {
( heta_j:= heta_j-alphasum_{i=1}^m(h_ heta(x^{(i)})-y^{(i)})x^{(i)}_j)
所有( heta_j)必须同步更新
}
-
高级优化算法
Given ( heta), we have code that can compute
- (J( heta))
- (fracpartial{partial heta_j}J( heta)) (for j = 0,1,...,n)
优化算法:
- Gradient descent
- Conjugate gradient
- BFGS
- L-BFGS
后三种算法的优点:
- 不需要选取学习率(alpha)
- 往往比梯度下降法快
缺点:
- 更复杂