Google深度學習筆記 Logistic Classification

Logistic Classification

Github工程地址:https://github.com/ahangchen/GDLnotes
歡迎star,有問題可以到Issue區討論
官方教程地址
視頻/字幕下載

About

simple but important classifier

  • Train your first simple model entirely end to end
  • 下載、預處理一些圖片以分類
  • Run an actual logistic classifier on images data
  • Connect bit of math and code

Detail

Linear Classifier

之所以這樣建模,是因爲線性公式是最簡單的數學模型,僅此而已。

  • Input: X (e.g. the pixels in an image)
  • Apply a linear function to X
    • Giant matrix multiply
    • Take inputs as a big vector
    • Multiply input vector with a matrix, W means weights
    • b means biased term
    • Machine learning adjust weights and bias for the best prediction
  • Output: Y, predictions for per output class

    • Y is a vector, represents the probability of each label
    • 好的預測中,正確的label的概率應當更接近1
    • 往往得到的Y一開始不是概率,而是一些具體值(scores/logits),所以需要轉換,by:

    Softmax迴歸模型:Wikipedia

Softmax

  • 代碼 soft_max.py:Softmax實現與應用
  • input的score差異越大(可以全部乘10試試),則輸出的各項label概率差異越大,反之差異越小
  • Softmax只關心幾個label之間的概率,不關心具體值
  • 機器學習是一個讓預測成功率升高的事情,因此是一個讓score之間差異增大的過程

One hot encoding

正確預測結果應當是只有一個label成立,其他label不成立。這種情況下,預測概率最大的則是最可能的結果。

Example: take this test

  • one hot encoding在label很多的情況下not work well,因爲output vector到處都是0,很稀疏,因此效率低
  • 好處:可以measure我們與理想情況之間的距離(compare two vectors)

    分類器輸出:[0.7 0.2 0.1] \<=> 與label對應的真實情況:[1 0 0]

  • Compare two vectors: cross-entropy

  • D(S, L) != D(L, S)

    Remember: Label don’t log, for label zero

小結

找到合適的W和b,使得S和L的距離D的平均值,在整個數據集n中最小。

最小化cross-entropy

D的平均值即是Training loss,求和和矩陣相乘是個大數據的活。

兩個參數的誤差導致一個呈圓形的loss,所以我們要做的就是找到儘量靠近圓心的weight

機器學習問題變成了一個數值優化
- 解決方法之一:Gradient descent,求導

修改參數,檢查誤差是否變大,往變小的方向修改,直到抵達bottom。

圖中weight是二維的,但事實上可能有極多的weight

下一節實踐

如果覺得我的文章對您有幫助,請隨意打賞~

圖片名稱

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章