TSUNG TANG CHOU
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # L1正則化 L2正則化 L1 正則化 L1 正則化 是機器學習中一種常用的正則化技術,用來防止模型過擬合,通過對模型的參數施加懲罰來控制模型的複雜度。 公式: L1 正則化會在損失函數中加入模型參數的絕對值和作為懲罰項。假設模型的參數為 ![image](https://hackmd.io/_uploads/rkTlV1zV1x.png) 那麼 L1 正則化項為: ![image](https://hackmd.io/_uploads/rkvQEyG4kx.png) ![image](https://hackmd.io/_uploads/SJbVEkfEyl.png) === L2 正則化 與 L1 正則化類似,L2 正則化 也是一種防止過擬合的技術,但它的懲罰方式不同。 公式: L2 正則化是將模型參數的平方和作為懲罰項: ![image](https://hackmd.io/_uploads/B1drN1MEkx.png) ![image](https://hackmd.io/_uploads/r1OI4JfVkg.png) === L1 與 L2 正則化的區別 1. 稀疏性: - L1 正則化會使一些權重變為 0,導致稀疏模型,適合特徵選擇。 - L2 正則化會讓所有權重變得很小,但不會變為 0,因此保留所有特徵。 2. 懲罰方式: - L1 正則化對權重的絕對值進行懲罰,因此對於那些不重要的特徵,會直接將其權重設為 0。 - L2 正則化對權重的平方進行懲罰,更加平滑地縮小權重。 3. 應用場景: - L1 正則化適合用於高維數據中的特徵選擇(如 Lasso 回歸)。 - L2 正則化適合控制權重大小,使模型更加平滑(如 Ridge 回歸)。 === 總結 - L1 正則化:對權重的絕對值進行懲罰,促使部分權重變為 0,實現特徵選擇並防止過擬合。 - L2 正則化:對權重的平方進行懲罰,縮小權重但不會使其變為 0,防止過擬合但保留所有特徵。 希望這些解釋能幫助您理解 L1 和 L2 正則化的區別及應用!如果還有問題,隨時告訴我! === 為什麼L1正則化可以讓一些權重變0? ChatGPT 說: ChatGPT L1 正則化 可以讓一些權重變為 0,這是因為 L1 正則化對權重的懲罰特性,具體來說,它會促使權重進行稀疏化(即部分權重趨向於 0)。這與 L1 正則化的數學性質和優化過程有關。 1. L1 正則化的數學懲罰特性 L1 正則化的懲罰項是每個權重的絕對值總和: ![image](https://hackmd.io/_uploads/SyPtE1MEke.png) - 由於對每個權重 Wi都施加了絕對值懲罰,優化過程中模型傾向於減小權重的大小,以減少這個懲罰項對損失函數的影響。 - 在這個過程中,當某些權重 Wi 的值很小時,為了最小化損失函數,L1 正則化會直接把這些權重推到 0,從而完全消除這些特徵對模型的影響。 2. 為什麼會出現權重變為 0? 這可以從 L1 正則化 與 L2 正則化 的幾何性質來理解: - L1 正則化對權重施加的是絕對值懲罰,這會產生一個「尖角形」的等值線,當我們進行優化時,模型在逼近損失最小點的過程中,會傾向於逼近這些「尖角」位置。這些尖角位置通常出現在權重為 0 的地方。因此,當優化過程逼近最優解時,L1 正則化會自動將一些小權重收縮到 0。 - L2 正則化 對權重施加的是平方懲罰,它的等值線是圓滑的,因此權重會逐漸縮小,但不會直接變為 0。 3. 優化過程中權重變 0 的原因 當我們使用 L1 正則化進行模型優化時,模型會根據損失函數的梯度來調整每個權重。由於 L1 正則化的梯度是固定的(不管權重是大還是小,L1 正則化的懲罰對小權重的影響都很強),因此,當某些權重值很小但還不為 0 時,正則化懲罰的作用會促使這些小權重直接變成 0。這種收縮效果讓 L1 正則化能夠選擇性地將不重要的特徵剔除。 4. 幾何解釋 可以通過幾何來直觀理解: - L1 正則化在多維參數空間中的等值線是一個菱形,當模型的優化目標接近菱形的頂點(即坐標軸上的點)時,優化過程會自然將某些權重推向 0。 - L2 正則化的等值線則是圓形或橢圓形,權重會被均勻縮小,但不會像 L1 那樣明顯被壓縮到 0。 5. L1 正則化與特徵選擇 正是因為 L1 正則化能夠使部分權重變為 0,所以它非常適合特徵選擇。當模型在學習時,它會自動識別哪些特徵對結果的影響較小,並將這些特徵的權重壓縮到 0,從而自動去除不重要的特徵,實現特徵選擇。 總結: - L1 正則化可以讓一些權重變為 0,是因為它對權重的絕對值施加懲罰,這使得優化過程會傾向於將較小的權重推向 0。 - 這種效果來自於 L1 正則化的幾何特性,促使模型在優化時選擇性地去除不重要的特徵,從而達到特徵選擇和防止過擬合的效果。 如果您對這個過程有進一步的疑問,請隨時告訴我! 4o 你說: 可以用高階直覺人類初學者可理解的方式說明嗎?而不要用複雜的數學理論 ChatGPT 說: ChatGPT 好的!讓我們用一個更直觀的方式來說明 L1 正則化為什麼能讓一些權重變為 0,而不用複雜的數學理論,這樣初學者會更容易理解。 簡單類比: 想像你是一位經理,負責一個項目。你有許多員工(每個員工就像是模型中的一個「權重」),有些員工非常重要,他們負責關鍵的工作;但有一些員工的貢獻很少,對項目影響不大。作為經理,你希望減少成本(也就是減少模型的複雜性),所以你想看看是否有不重要的員工可以讓他們離開公司。 L1 正則化 就像一個經理,它會仔細檢查每個員工的貢獻(也就是權重的大小)。當發現某些員工貢獻很少的時候,它就會決定把這些員工「解雇」,也就是把這些小的權重設為 0。這樣只剩下那些對項目真正有用的員工(即對模型預測結果影響較大的權重)留在團隊中。 為什麼 L1 正則化會「解雇」小的權重? 當你試圖簡化模型時,L1 正則化會評估每個特徵的權重。如果某個權重非常小,說明這個特徵對結果幾乎沒有影響。L1 正則化的目標是讓模型變得簡單且有效,所以它會「選擇性地」把這些權重設為 0,這就像是解雇那些不太有用的員工一樣。結果是,模型只留下真正重要的特徵,而那些不重要的特徵則被自動移除。 為什麼 L1 正則化能這麼做,而 L2 正則化不能? 想像 L2 正則化就像是一位和善的經理,看到貢獻少的員工時,他不會解雇他們,而是溫和地減少他們的工作量(也就是縮小權重)。這樣所有員工還在工作,只是工作量減少了,但沒有人被解雇。因此,L2 正則化會讓所有權重變得較小,但不會完全設為 0。 相比之下,L1 正則化就像一個更嚴厲的經理,會直接「解雇」貢獻很小的員工,因此一些權重會直接變為 0。 總結: - L1 正則化 就像是一位只想要保留重要員工的經理,它會「解雇」那些貢獻小的員工,讓他們的權重變成 0,從而簡化模型。 - 這樣,L1 正則化幫助模型自動去除不重要的特徵,只留下對預測結果有明顯影響的部分。 - 相比之下,L2 正則化 只是減少所有權重的大小,但不會讓任何權重變成 0。 這樣的方式,應該能更直觀地幫助理解 L1 正則化的作用。如果還有問題,請隨時告訴我! 4o 你說: 那絕對值為何在L1正則稱為懲罰,具體效果是什麼,因為我只看的出會讓負值變正,這樣權重總和只會有正數,而且會越來越大不是嗎? ChatGPT 說: ChatGPT 這是一個非常好的問題!我們來更直觀地解釋為什麼 L1 正則化中的絕對值是懲罰,以及它的具體效果。 1. 為什麼在 L1 正則化中使用絕對值作為懲罰? 首先,L1 正則化是透過 絕對值來懲罰權重的,這是因為絕對值有兩個特點: 1. 避免正負號的影響:我們希望處理的是權重的「大小」,而不是它是正數還是負數。使用絕對值後,無論權重是正還是負,都會對模型產生相同的影響。這樣能夠讓 L1 正則化聚焦於權重的大小,而不會因為某個權重的符號不同(正或負)而產生偏差。 2. 產生稀疏性:L1 正則化的關鍵在於它能促使某些權重變為 0,這是因為它會讓模型更傾向於將不重要的特徵(權重)收縮到 0。這樣,L1 正則化能自動挑選出對預測貢獻最大的特徵,忽略不重要的特徵。 2. 懲罰效果: 我們常說懲罰,是因為 L1 正則化會讓模型在優化過程中對較大權重產生更大的代價。當你增加權重的絕對值,L1 正則化會額外給這些大的權重加上一個「懲罰」,使得它們變得不那麼優化。 具體效果: - L1 正則化的懲罰效果其實不在於讓權重變得「越來越大」,而是使權重在訓練過程中盡量縮小,並且對不重要的特徵進行「懲罰」,將它們的權重縮小到 0。這個懲罰來自於模型的優化過程,模型會選擇降低那些不重要權重的值,並將它們推向 0。 - 在這個過程中,模型不僅會尋求最小化損失函數,還會通過 L1 正則化的懲罰項,讓不重要的權重變為 0,從而去除不必要的特徵。 3. L1 正則化如何工作? 假設我們有一個簡單的損失函數,它是由 預測誤差和 L1 正則化項構成的: ![image](https://hackmd.io/_uploads/By1sVJGV1g.png) - 預測誤差:這是模型的預測結果和真實結果之間的差異,模型會通過這個來最小化誤差。 - L1 正則化項:$\lambda \sum_{i=1}^{n} |W_i|$ 是對模型權重的懲罰。這個項越大,懲罰越強,權重會被壓縮到 0。 如何讓權重變 0? 1. 權重的絕對值越大,懲罰越大:當某個權重 Wi的絕對值越大,L1 正則化會給它越大的懲罰,這樣模型就會尋求將權重 Wi 減小。 2. 模型會自動壓縮小貢獻的權重:模型會調整這些權重,將它們縮小。對於那些對預測貢獻極小的特徵(權重小的特徵),L1 正則化會強烈迫使它們的權重縮小到 0。 4. L1 正則化的直觀理解 想像一下,在一個 多維空間中,模型的目標是找到最優的權重。L1 正則化會把所有的權重都推向原點(即 0)。具體來說,對於某些特徵,L1 正則化會將它們的權重收縮到 0,這樣這些特徵就不再對預測有影響,從而完成特徵選擇。 這個過程就像是選擇那些最有價值的特徵,忽略那些貢獻極小的特徵,這樣模型變得更加簡單且有用。 === 總結: - L1 正則化中的絕對值是為了消除正負號的影響,並強迫模型在訓練過程中將一些權重縮小到 0。 - 它的懲罰效果會讓模型在學習時,不斷調整權重,減少不重要特徵的影響,並自動去除它們。 - L1 正則化促進了稀疏性,有助於特徵選擇,這是它的最大優勢。 希望這樣的直觀解釋能幫助您理解 L1 正則化!如果還有其他問題,隨時告訴我! === 最早就是想了解以下例子,才關連到L1 L2 例子:兩點之間的距離和 MSE 假設我們有兩個點,分別是實際值(真實數據)和預測值。我們想要比較它們之間的距離,並計算 MSE。 情境設定: - 實際值:($x_{\text{實際}}$, $y_{\text{實際}}$) = (3, 4) - 預測值:($x_{\text{預測}}$, $y_{\text{預測}}$) = (1, 1) ![image](https://hackmd.io/_uploads/BJ4CVyzV1e.png) 我們將這兩個點看作平面上的兩個坐標點,並計算它們之間的距離。 ![image](https://hackmd.io/_uploads/S1XJSkfE1g.png) ![image](https://hackmd.io/_uploads/BkKyr1GVJg.png) 以上一個例子 MSE,只有一個點 為何要除以2呢? 您提到的這個問題非常好!在我之前的例子中,確實不應該將均方誤差(MSE)除以 2,因為我們只有一個數據點。除以 2 的錯誤操作通常是在某些損失函數中(例如 L2 正則化)為了方便求導而進行的技術處理,而不是 MSE 的標準計算方法。 ![image](https://hackmd.io/_uploads/By_xHyGEke.png) 為什麼會有除以 2 的情況? 在某些損失函數(如 L2 正則化或均方誤差的某些變體)中,為了簡化反向傳播中的導數計算,會將損失函數中的平方項除以 2。這樣在求導時,2 和平方中的 2 會相互抵消,導數計算更為簡潔。但這是出於技術性操作,而不是標準的均方誤差計算方式。 總結: - 標準 MSE 不需要除以 2,應該是誤差的平方和,然後除以數據點數量。 - 除以 2 的情況通常出現在其他損失函數中(例如 L2 正則化),是為了簡化導數計算。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully