17.大量數(shù)據(jù)機器學習(Large scale machine learning)

第10周 Lecture 17 大量數(shù)據(jù)機器學習

  1. 隨機梯度下降(stochastic gradient descent)
    步驟:
    a.)訓練數(shù)據(jù)重新隨機排列(Randomly shuffle(reorder) training examples)
    b.) 算法描述
    cost(\theta, (x^{(i)}, y^{(i)}))=\frac12(h_\theta(x^{(i)})-y^{(i)})^2
    J_{train}(\theta) = \frac1{2m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2
    Repeat \{ //1 - 10 次
    \ \ \ \ \ \ \ \ \ for \ i:=1,...,m \ \{
    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \theta_j := \theta_j - \alpha(h_\theta(x^{(i)}-y^{(i)})x_j^{(i)} // (for every j=0, ...,n)
    \ \ \ \ \ \ \ \ \ \ \}
    \ \ \ \}
    和正常的梯度下降比起來,下降是隨機的,但是最后還是可以到最低點,但這個不需要每下降一步都對所有訓練數(shù)據(jù)重新計算,所以速度會快很多。
    image.png

c.) 對比批量梯度下降(batch gradient descent)
J_{train}(\theta) = \frac1{2m}\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})^2
Repeat \{
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \theta_j := \theta_j - \alpha \frac1m\sum_{i=1}^m(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)} // (for every j=0, ...,n)
\ \ \}

  1. 小批量梯度下降(Mini gradient descent)
  • Batch gradient descent: 每一步使用所有的訓練集
  • stochastic gradient descent: 每一步使用1個訓練集
  • Mini gradient descent: 每一步使用b個訓練集
    算法描述:
    假設 b = 10 , m = 1000,
    Repeat \{
    \ \ \ \ \ \ \ \ \ for \ i:=1,...,991 \ \{
    \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \theta_j := \theta_j - \alpha \frac1{10}\sum_{k=i}^{i+9}(h_\theta(x^{(k)}-y^{(k)})x_j^{(k)} // (for every j=0, ...,n)
    \ \ \ \ \ \ \ \ \ \ \}
    \ \ \}
  1. 隨機梯度算法如何知道在收斂
  • 建議每1000次,計算一次代價函數(shù),畫出曲線,是否收斂
  • 隨著運算次數(shù),減少學習率(\alpha),例如\alpha = \frac{const1}{步數(shù)+const2}
    image.png
  1. 在線學習(online learning)
  • 每天的數(shù)據(jù)都比較大,按每天的數(shù)據(jù)重新計算
  • CTR 點擊率預測學習 learning the predict


    image.png

    image.png
  1. Map-reduce and data parallelism
    把數(shù)據(jù)分在不同的機器同時進行計算,完成計算后,再求和
    例如對于梯度下降
    m = 400
    \theta_j := \theta_j - \alpha \frac1{400}\sum_{i=1}^{400}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
    把400條數(shù)據(jù)分成4份,每份100條,分在4臺機器同時運行,4臺完成后,再求和。只要算法可以拆分
    其中對于機器1
    temp_j^{(1)} = \sum_{i=1}^{100}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
    temp_j^{(2)}= \sum_{i=101}^{200}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
    temp_j^{(3)}= \sum_{i=201}^{300}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
    temp_j^{(4)}= \sum_{i=301}^{400}(h_\theta(x^{(i)})-y^{(i)})x_j^{(i)}
    合并后
    \theta_j := \theta_j - \alpha \frac1{400}(temp_j^{(1)} +temp_j^{(2)} +temp_j^{(3)} +temp_j^{(4)} )
    image.png
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容