Gradient descent and others
阿新 • • 發佈:2019-03-17
循環 目的 over math des 次數 mini 們的 機器 學習路\(\alpha\)
Batch gradient descent
Procedure
- 在循環中跌倒公式\(\theta_j:=\theta_j-\alpha{1\over{m}}\sum_{i=1}^m(h_{\theta}(x^{(i)})-y^{(i)})x_j^{(i)}\)
- 只有叠代完所有的數據, 才更新\(\theta\)
Stochastic gradient descent
Procedure
- 將原始數據打亂
- 在循環中跌倒公式\(\theta_j:=\theta_j-\alpha(h_{\theta}(x^{(i)})-y^{(i)})x_j^{(i)}\)
- 與Batch梯度下降的公式不同, 少了\(\sum_{i=1}^m\)
Mini-batch gradient descent
Features
- 新增了b變量, 表示每一次叠代b個樣本
Procedure
- 選定好b
- 使用for循環語句, for i = 1, 1+b, ..., 叠代公式\(\theta_j:=\theta_j-\alpha{1\over{b}}\sum_{k=i}^{k+b}(h_{\theta}^{(k)}-y^{(k)})x_j^{(k)}\)
學習路\(\alpha\) 的選擇
- 可以確定兩個常量const1和const2
- 公式\(\alpha={const1\over{iterNum+const2}}\)
- 好處, 當我們叠代的次數增加, \(\alpha\)會自動的減小
Loss Function與Cost Function
- Loss Function一般使用L表示, 它表示的是單個樣本的損失
- Cost Function一般使用J表示, 它表示的是所有樣本的損失
- 在機器學習中, 我們的目的是優化J
Gradient descent and others