s1byl
    • 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
    # [ML] 機器學習簡介 ###### tags: `ML` **人工智慧**(artificial intelligence, AI),指由人製造出來的機器所表現出來的智慧。通常指的是透過電腦程式來呈現類似於人類智慧的技術。 **機器學習**(machine learning, ML)是 AI 的一個實現途徑,也就是說,我們可以透過機器學習來達成人工智慧。手段是讓電腦從資料當中反複學習,透過各種演算法來識別**已看過的資料**中的模式,進而在**未看過的資料**上預測結果。 在這邊我會先建立一個對機器學習的概觀,並介紹幾類常見的機器學習演算法。 ## 機器學習的框架 要在產業上應用機器學習,無論運用的是何種演算法,大致上都會經過以下的步驟: * 對問題的了解 為何使用機器學習,以及想處理怎樣的問題。 * 蒐集與清理資料 首先要有足夠的資料量,然後資料要盡可能抽取乾淨,才能夠得出想要的 insight。 * 特徵選擇 決定您需要提供什麼樣的資料給電腦來建立模型。這步驟會隨著選用的演算法不同,而要提供不同的特徵給電腦,甚至是對特徵進行不同的處理。 * 模型挑選 選擇已經訓練好的檔案(模型)來處理資料並尋找資料中的某些東西。模型當中包含了所要用的演算法,然後測試資料再將兩者結合,進而得出結論。 * 訓練與調校 檢查模型所得出的結論,調整提供給模型的一些值(稱為超參數),以確保得到的是想要的答案。 * 評估模型與演算法 決定模型是否已經成熟可用,或者是否需要再回頭修正模型、特徵、演算法或資料,來達成您的目標。 * 模型部署 將訓練好的模型部署到營運環境。 * 線上評估 檢討營運環境現有模型的輸出結果。 ## 機器學習的種類 ![](https://hackmd.io/_uploads/B1EuWIEoq.png) ### 監督式學習 ![](https://hackmd.io/_uploads/SJLEDUEs5.png) 監督式學習(supervised learning)是電腦從有標籤的 資料中分析模式後做出預測的學習方式。標記過的資料就好比標準答案,電腦在學習的過程透過對比誤差,一邊修正去達到更精準的預測。 舉例來說,現在我們想訓練一個模型對一些貓或狗的照片進行分類,如果用的是監督式學習的方式,我們會丟給電腦一堆標記了「上面有貓」或是「上面有狗」的照片(假設只會有一種動物),讓電腦知道「上面有貓」和「上面有狗」的照片分別會有怎樣的特徵(比如說尾巴的形狀、耳朵的形狀等,也有可能是人類無法看出的特徵),這樣一來,之後電腦再看到其他貓或狗的照片時,就能分辨出是貓還是狗了。 監督式學習需要倚靠大量的事前人工標記作業,這過程相當繁複,成本也很高昂。當範圍擴大、資訊量增加,會更難去對資料標記出所有特徵,所以在面對未知領域時,幾乎是完全無法運作。 ### 非監督式學習 ![](https://hackmd.io/_uploads/H1XUP8Njc.png) 非監督式學習(unsupervised learning)的訓練資料不需要事先以人力處理標籤,機器面對資料時,做的處理是依照關聯性去歸類、找出潛在規則與套路、形成集群 (Clustering),不對資訊有正確或不正確的判別。 同樣以貓狗照片分類的案例來說明,現在同樣餵給電腦一堆貓狗的照片,但不同的是,非監督式學習不告訴電腦照片上的動物是貓還是狗,只讓電腦自己去發現這些照片上的動物有什麼不同、分別是哪些特徵不同。我們可以告訴電腦有兩類不同的群體(貓和狗),希望電腦能自然而然藉由特徵的不同,將照片分成兩個互斥的類別。 非監督式學習的特性讓它在資料探勘初期是好用的工具。對比監督式學習,非監督式學習可以大大減低繁瑣的人力工作,找出潛在的規則。但這樣的方式,也會造成較多功耗,甚至,也可能造成不具重要性的特徵被過度放大,導致結果偏誤、無意義的分群結果。 ### 強化學習 ![](https://hackmd.io/_uploads/SkN9vL4i5.png) 強化學習(reinforcement learning, RL)是以環境回饋作為輸入,在不藉助監督者提供完整的指令之下,自行發掘在何種情況下該採取何種行動以獲取最大報酬,並適應環境的機器學習方法。 與監督學習不同的是,強化學習不需要帶標籤的輸入輸出對,同時也無需對非最優解的精確地糾正。其關注點在於尋找探索(對未知領域的)和利用(對已有知識的)的平衡,也就是所謂的探索-利用(exploration-exploitation)的交換(tradeoff)。 ## 常見的機器學習演算法 ### 線性迴歸 線性迴歸(linear regression)屬於一種監督式學習的演算法。以二維平面上的線性迴歸為例,給定平面上的一些點,若以直線去趨近資料,則稱為線性迴歸;若是以多項式曲線趨近資料,則為多項式迴歸。一般在操作慣例上會移除掉相關度非常高的變數以及離群值,以提高精確度。 舉例來說,我們想要用直線 $y=\beta_0 + \beta_1 x$ 來描繪平面上這些點的趨勢,其中 $\beta_0$ 為截距(intercept),$\beta_1$ 則是斜率(slope),也就是 $x$ 變動一個單位時 $y$ 會跟著變動的量。 ![](https://hackmd.io/_uploads/BkvcT8Vj5.png) 為了量化我們的直線逼近這些點的趨勢的程度,需要一個優化的目標函數,也就是所謂的損失函數(loss function),這個值越小越好。通常我們會用mean squared error(MSE)來作為線性迴歸的loss function,而這就是一般說的最小平方法:最小化所有點到直線在y方向上的error的平方和。 ### K-最近鄰 K-最近鄰(k-nearest neighbor, KNN)演算法是一種監督式學習演算法,可以用於分類或迴歸。 KNN 的分類是一種投票,考慮 k 個最近的鄰居來判定新的資料是在哪一群。其演算法流程非常簡單,首先使用者先決定 k 的大小。接著計算目前該筆新的資料與鄰近的資料間的距離。第三步找出跟自己最近的 k 個鄰居,查看哪一組鄰居數量最多,就加入哪一組。k 的大小會影響模型最終的分類結果。 ![](https://hackmd.io/_uploads/rJkC7PVi9.png) KNN 的迴歸模型輸出的結果是一個連續性數值,其預測該值是 k 個最近鄰居輸出的平均值。 ### 決策樹 決策樹(decision tree)是一種監督式學習演算法,通常被用於分類問題。 ![](https://hackmd.io/_uploads/SJ34IPVoc.png) 上圖顯示的就屬於一個決策樹。 決策樹的模型使用貪婪法則來決定每一層要問什麼問題,目標是分類過後每一群能夠很明顯的知道是屬於哪一種類別。延續上面的例子,以分類問題來說假設要評估明天比賽是否舉行。在樹的第一層節點中我們要從已知的兩個特徵分別是溫度與特徵選一個作為該層的決策因子。 假設目前訓練集有五筆資料,其中正常舉行的有2筆資料,取消舉行的有3筆資料。在樹的結構中左子樹為決策正常取行,而右子樹是決策取消舉行。 ![](https://hackmd.io/_uploads/BkZjIw4iq.png) 假設按照濕度和天氣兩種特徵來分類結果如上圖,我們可以發現當特徵為天氣的時候可以一很清楚的將這兩類別完整分開,因此我們會將天氣作為這一層判斷的因子。這就是決策樹在生成中的貪婪機制。只要保證在每一個分支都按照這個機制來生成,那我們就可以得到一個最好的決策樹。 ### K-means ![](https://hackmd.io/_uploads/SJgs_vEs9.png) K-means 是一種非監督式的分群(clustering)演算法。步驟如下: 1. 我們先決定要分k組,並隨機選k個點做群集中心。 2. 將每一個點分類到離自己最近的群集中心。 3. 重新計算各組的群集中心(重心)。 反覆 2、3 動作,直到群集不變,群集中心不動為止。 可以參考一個k-means訓練過程的動畫:[連結](https://www.youtube.com/watch?v=nXY6PxAaOk0)。 ### 深度學習 深度學習(deep learning)指的不是一種演算法,而是使用深度神經網路完成機器學習任務的統稱。維基百科這麼說: > 「深度學習」已成為時髦術語,或者說是人工神經網路的品牌重塑。 可以把深度學習形容成一種「比較深」的類神經網路,並搭配了各式各樣特別的類神經網路階層,如卷積神經網路、遞歸神經網路等等。 #### 神經網路 神經網路(neural network, NN)是參考生物神經系統的結構,神經元(neuron)之間互相連結,由外部神經元接收信號,再層層傳導至其他神經元,最後作出反應的過程。 ![](https://hackmd.io/_uploads/BknXXMSs5.png) 在神經網路中,通常會有數個階層,每個階層中會有數十到數百個神經元,神經元會將上一層神經元的輸入加總後,進行一個非線性的轉換,當成神經元的輸出。每個神經元還會透過 activation function 進行一個非線性的變換,例如 sigmoid、tanh 和 ReLU 等。 ![](https://hackmd.io/_uploads/H1sYGzBj9.png) 神經網路的架構指的就是階層數量、每層中的神經元數量、各層之間神經元的連接方式、及活化函數的類型等設定。這些參數設定都是在使用神經網路前需要由人力設定好的,參數設定的好壞也是大大影響到神經網路的效能表現。神經網路的學習和訓練過程就是試著找到最佳的權重設定。 #### 卷積神經網路 卷積神經網路(convolutional neural network, CNN)是最常見的深度學習網路架構之一,因為網路架構中的卷積層(convolutional layer)及池化層(pooling layer)強化了模式辨識及相鄰資料間的關係,使卷積神經網路應用在影像、聲音等類型的資料型態能得到很好的效果。 Hubel和Wiesel在60年代研究貓腦皮層時,發現了一種獨特的神經網路結構,可以有效地降低神經網路的複雜性,進而提出了CNN。現在,CNN已經發展成一種高效的圖像識別方法。 一個CNN的基本結構如下所示: ![](https://hackmd.io/_uploads/r1lQHMrjc.png) ![](https://hackmd.io/_uploads/HJ74HMriq.png) CNN包含2種特殊的結構層:卷積層和池化層。卷積層由多個特徵平面構成,完成抽取特徵的任務。池化層中的神經元對其接受域中的資料進行抽樣(例如,取大,取小,取平均值,等等),因此經過池化層後神經元的個數往往會減半。對於每個神經元,定義了相應的接受域,只接受從其接受域傳輸的信號。 卷積層是卷積神經網路最核心的部份,通常由數十到數百個$n \times n$的 filter 組成,每個濾鏡會對不同的影像模式進行強化,這些濾鏡實際強化的影像模式也是由訓練過程找出來的,所以卷積層可以針對不同的問題產生出不同的濾鏡效果。 ![](https://hackmd.io/_uploads/HJfpHzSs5.png) 可以參考一個CNN如何運作的動畫:[連結](https://www.youtube.com/watch?v=f0t-OCG79-U)。 #### 遞歸神經網路 遞歸神經網路(recurrent neural network, RNN)吃的是序列式的資料。在RNN的架構裡,加入了一個記憶空間(hidden State)。這個記憶空間不能容納太多資訊,但他會儲存上一次的輸出。 ![](https://hackmd.io/_uploads/ryISufHsq.png) RNN每一次輸出的時候,他都會先參考記憶空間裡面的資訊,也就是上一次輸出了什麼。這讓RNN能夠學習到與前文之間的對應關係。但很顯然,如果只有上一次是不夠的,我們需要把一整句話都輸入進去RNN,讓RNN分別理解後,輸出我們想要的輸出,可以當成一種翻譯的過程。 這時候我們會把給RNN輸入接口的句子,一個字一個字的丟進去RNN中,直到把一整個句子全部輸入進去。 在實務上,我們會先預設句子有多長,比如說句子最長可能有20個字,我們就創造一個長度為20的空間來儲存句子。而如果句子小於20個字,我們就把空缺的部分補上停止字元和空白字元。這樣 RNN在讀到停止字元時,就知道需要翻譯的句子已經讀完了。 然後RNN對於每一個字都會產生一個輸出,只是在讀到停止字元前,所有輸出都會被隱藏起來。而當讀到停止字元,RNN會把最後一次的輸出值輸出,讓使用者得到他想要的資訊。

    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