蝦想承為工程師
    • 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
    • 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
    • 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
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
  • 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
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ## 什麼是集成學習(Ensemble learning)? 在機器學習中,單一模型往往有其局限性,而集成學習的目的是將多個模型的預測結果進行整合,達到比單獨使用一個模型更好的效果,也就是常常聽到的一句諺語「三個臭皮匠勝過一個諸葛亮」。 集成學習主要分成三個方法,以下先做簡單介紹 1. Bagging: 透過多次隨機且重複抽樣產生多組訓練數據集(training set),並訓練多個模型,最終取模型預測結果的「平均值(回歸)」或「投票結果(分類)。」 2. Boosting: 透過依次訓練弱分類器,每次針對前一次的錯誤進行加權,最終生成一個強分類器。 3. Stacking: 透過使用不同的模型進行訓練,然後將這些模型的輸出作為下一層模型的輸入,從而提高預測精度。 ## Bagging ### Bootstrapping 假如你手上有一組 N 筆的原始資料(Original data),透過隨機且取後放回的規則去抽出 n 筆資料(通常 N = n),即可得到一個新的資料集,若重複以上的動作就可以建構出多個資料集,此步驟稱為「Bootstrapping」,接著將剛剛建構出的資料集訓練各自不同的 model,例如決策樹(Decision tree)、支持向量機(SVM)等,最後將這些訓練好的模型整合起來,成為一個強大的 Ensemble model。 ### Aggregating 現在有一筆從未看過的資料,希望模型能預測出較佳的結果,這個結果可能是一個數值或者是類別,根據問題/任務的特性而定,如果輸出結果為一個數值,則將每個小模型的輸出結果平均(Average of outputs)得到最終結果,如果輸出結果為一個類別,則將每個小模型的輸出結果依照多數決(Majority vote)得到最終結果,此步驟稱為「Aggregating。」 ### Bagging = Bootstrapping + Aggregating 因此,Bagging 的核心概念就是 Bootstrapping 與 Aggregating 的技術組合而成,透過隨機且取後放回的抽樣方式,訓練不同的模型,採用平均或是多數決的方式決定最終結果,降低模型發生過擬合(Overfitting)的可能性,也就是降低方差(Variance),避免原始資料(Original data)中離群點(Outlier)的影響。 有關 Overfitting 與 Variance 的關係,詳細內容請參見[Overfitting v.s. Underfitting](https://hackmd.io/@lcaMuWOwR1Ox5o5yeTEupA/ByCVKNQNA) 的文章。 ![image](https://hackmd.io/_uploads/BkjkZ1O0C.png) <p class="text-center">Bagging(Source: AIML.com Research) :::info 常聽到的隨機森林(Random Forest, RF),其實就是應用 Bagging 技術的其中一個例子,簡單來說 Random Forest = Bagging + decision tree,其運作方式是構建多棵決策樹(即"森林"),並通過這些樹的預測結果進行集成,達到更精確和穩定的預測。 需要特別注意的是,隨機森林的隨機性體現在隨機抽樣以及隨機特徵選擇,隨機抽樣能減少模型過度擬合,隨機特徵選擇降低決策樹之間的相關性,若原始資料(Original data)具有 p 個特徵的分類問題,構建決策樹常使用 √p 個特徵,而回歸問題常使用 p/3 個特徵。 ::: ## Boosting 根據前一輪分類器預測錯誤的數據,賦予錯誤樣本更高的權重,讓下一個分類器更加專注於修正這些錯誤,也就是說這些不同的分類器(classifier)為互補關係,後分類器彌補前分類器不足之處,依序訓練,最後整合出強大的分類器。 保證,如果有一個弱小的分類器(ex: 淺層決策樹)在訓練資料上的錯誤率(Error rate)小於 50%,其偏差(bias)也很高,經過 Boosting 後,最終能獲得一個錯誤率為零的強大分類器,使得偏差能有效降低。 ![image](https://hackmd.io/_uploads/BJpQ-EK0A.png) Boosting 算法常見的分為以下三種 ### 1. AdaBoost(Adaptive Boosting) 最早的 Boosting 算法,每個新的分類器專注於前一個分類器錯誤分類的樣本,為錯誤樣本賦予較高權重,從而改善整體模型的準確性。 下圖中,一開始各個數據點的權重都是相同的,經過第一個分類器的判讀結果,錯誤率為 0.3,判讀錯誤的數據會更新權重,其計算方式為$\exp\left(0.5 \cdot \ln\left(\frac{0.3}{0.7}\right)\right)=1.53$ 使其比一開始的權重大,而判讀正確的數據也會做一次權重更新,其計算方式為 $\exp\left(-0.5 \cdot \ln\left(\frac{0.3}{0.7}\right)\right)=0.65$ 使權重變小,因此下一個分類器將會更專注於權重較大的數據,也就是被錯誤分類的數據,彌補前一個分類器的不足之處,以此類推。 ![image](https://hackmd.io/_uploads/BylDAiu661x.png) ### 2. Gradient boosting Gradient boosting 的技術能夠使用在回歸、分類以及 Ranking 上,下方以回歸作為例子展示。 在迴歸問題中,首先產生一個初始模型(通常比深度僅有一層的決策樹 Stump 再深一些),使用原始資料的平均值作為預設值,並計算與每一筆實際值間的殘差。 根據計算出的殘差或梯度,訓練一個新的弱學習器(Weak learner),新的弱學習器的預測結果會被加入到整體模型的預測中,但在相加之前,會按學習率(learning rate)進行縮放,學習率通常介於 0.01 到 0.3 之間。 這樣的步驟會不斷重複:計算殘差或梯度、訓練新的弱學習器、更新模型,直到達到指定的迭代次數或滿足預定的停止條件。 ![image](https://hackmd.io/_uploads/BkPvgCoA0.png) :::info XGBoost(eXtreme Gradient Boosting) 是一種以梯度提升(Gradient Boosting)為基礎的機器學習方法,不僅保留了傳統梯度提升的優點,還加入了二階導數優化、正則化、缺值處理與並行運算等改良,使其在效率與準確率上都表現優異。 ::: :::info AdaBoost 和 Gradient Boosting 的差異 ![image](https://hackmd.io/_uploads/rkfp3uTpJx.png) ::: ## Stacking 首先準備建模資料,並將其劃分為訓練集、驗證集和測試集,接下來是選擇在堆疊模型中使用的基本模型(Base model),通常選擇多種異質模型(Heterogeneous model),確保它們產生不同類型的錯誤,並能相互彌補之間的問題。 選擇好基礎模型後,這些模型會在訓練集上進行訓練,當基礎模型訓練完成後,會使用這些模型對驗證集進行預測,並使用這些預測結果作為輸入並訓練元模型(Meta/Second-level model),元模型可以採用任何演算法來實現,例如線性迴歸、邏輯迴歸或神經網絡。 最終,元模型會用來對測試集進行預測,並根據基礎模型的輸出產生最終預測結果,最後,通過混淆矩陣等評估指標,對 Stacking 的性能進行評估。 ![image](https://hackmd.io/_uploads/SJovDAi0C.png) ### Stacking 的優點與缺點 優點 1. 性能提升:透過結合不同模型的預測結果,通常能獲得比單一模型更好的性能,特別是在複雜數據集上。 2. 靈活性:可以使用多種不同類型的模型(例如,決策樹、隨機森林和神經網絡),增加了模型的多樣性。 3. 減少過擬合:適當的堆疊可以減少模型的過擬合,尤其是在使用交叉驗證的情況下,能提高泛化能力。 缺點 1. 計算開銷大:訓練多個模型和元模型需要較高的計算資源和時間,可能不適合處理非常大的數據集。 2. 複雜性:模型的組合和調參可能相當複雜,需要更多的專業知識。 ## 總結 以上,解釋了什麼是集成學習(Ensemble learning),訓練多個學習器/小模型最後整合成一個強大的模型,正所謂「三個臭皮匠勝過一個諸葛亮」,也提到三個常用的機器學習算法,分別是 Bagging、Boosting 與 Stacking,並且說明其差異與優缺點。 --- :::info 以上就是這篇文章「集成學習(Ensemble learning): Bagging, Boosting and Stacking」的所有內容,第一次看的人會花比較多時間消化吸收,這是很正常的事情,若有任何問題,歡迎在下方與我聯繫、討論,接下來也會繼續分享相關文章,敬請期待。

    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 Google 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