17.大量數(shù)據(jù)機(jī)器學(xué)習(xí)(Large scale machine learning)

第10周 Lecture 17 大量數(shù)據(jù)機(jī)器學(xué)習(xí)

  1. 隨機(jī)梯度下降(stochastic gradient descent)
    步驟:
    a.)訓(xùn)練數(shù)據(jù)重新隨機(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)
    \ \ \ \ \ \ \ \ \ \ \}
    \ \ \ \}
    和正常的梯度下降比起來,下降是隨機(jī)的,但是最后還是可以到最低點(diǎn),但這個(gè)不需要每下降一步都對(duì)所有訓(xùn)練數(shù)據(jù)重新計(jì)算,所以速度會(huì)快很多。
    image.png

c.) 對(duì)比批量梯度下降(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: 每一步使用所有的訓(xùn)練集
  • stochastic gradient descent: 每一步使用1個(gè)訓(xùn)練集
  • Mini gradient descent: 每一步使用b個(gè)訓(xùn)練集
    算法描述:
    假設(shè) 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. 隨機(jī)梯度算法如何知道在收斂
  • 建議每1000次,計(jì)算一次代價(jià)函數(shù),畫出曲線,是否收斂
  • 隨著運(yùn)算次數(shù),減少學(xué)習(xí)率(\alpha),例如\alpha = \frac{const1}{步數(shù)+const2}
    image.png
  1. 在線學(xué)習(xí)(online learning)
  • 每天的數(shù)據(jù)都比較大,按每天的數(shù)據(jù)重新計(jì)算
  • CTR 點(diǎn)擊率預(yù)測學(xué)習(xí) learning the predict


    image.png

    image.png
  1. Map-reduce and data parallelism
    把數(shù)據(jù)分在不同的機(jī)器同時(shí)進(jìn)行計(jì)算,完成計(jì)算后,再求和
    例如對(duì)于梯度下降
    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臺(tái)機(jī)器同時(shí)運(yùn)行,4臺(tái)完成后,再求和。只要算法可以拆分
    其中對(duì)于機(jī)器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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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