iT邦幫忙

2023 iThome 鐵人賽

DAY 4
0

正規化可減少模型overfitting的問題

L1 regularization (Lasso)

  • 加入L1正規化 (loss function + L1 regularization)
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280J5vL1EZxdN.png

  • get gradient 對w做偏微
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280BpKgbNOOJo.png

    • w > 0, 結果為1 ; w < 0, 結果為-1 ; w = 0, 結果為0
    • sgn(x) 判斷實數正負號
  • 每次更新
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280HVTLivrxno.png

    • learning rate 通常是正的
    • 正規化係數通常也是正的
    • 如果 sgn(w) = 1 -> w ↓
    • 如果 sgn(w) = -1 -> w ↑

L2 regularization (Ridge)

  • 加入L2正規化 (loss function + L2 regularization)
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280CM4ZFFVv8z.png
  • get gradient 對w做偏微 (我手寫的見諒)
    • 關於為甚麼有1/2 (與2做消除)
      https://ithelp.ithome.com.tw/upload/images/20230919/2016328049BVIImtq7.png
  • 每次更新
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280o10nmEsxbu.png
    • learning rate 通常是正的
    • 正規化係數通常也是正的
    • 1 - learning rate * regularization coefficient < 1
      -> w ↓ (原w越大,計算後改變越多)

Lasso & Ridge

  • lasso
    • 不論參數大小,下降速度一致
    • 結果會有接近0的,也會有很大的值
  • ridge
    • 參數大,下降較快; 參數小,下降較慢
    • 結果會保留很多很小的值

Elastic net

  • loss function + L1 regularization + L2 regularization
    https://ithelp.ithome.com.tw/upload/images/20230919/20163280B5Hj3SR8sz.png
    • lasso 下降速度不一致,可能導至相關性高的不同變數僅保留一部分(會執行變數挑選)
    • ridge 產生多個很小的值,w會一起下降(皆降低)
  • 總結: Elastic Net綜合了Ridge 的正規化以及Lasso 的變數挑選

參考資料


上一篇
Day3-線性回歸 (Linear Regression)
下一篇
Day5-線性回歸(Linear Regression)與L1、L2 regularization & Elastic net實作 + jupyter notebook路徑&瀏覽器設定教學
系列文
什麼演算法?一起來學機器學習!30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言