mikechantw
    • 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

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

    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.
    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
    # Day11 & Day15~17 ###### tags: `cupoy`, `ML100` :::info + [Teams 會議連結](https://teams.live.com/meet/953218663186) + 2022-02-17 19:30 + ## ::: [TOC] ## D11:EDA: 數值填補與連續數值標準化 ### 重點 + 如何處理例外值 常用Python填補統計值的方法 ![](https://i.imgur.com/r8STIfv.png) + 連續型數值標準化 為何要標準化 改變一單位的 x2 對 y 的影響完全不同 ![](https://i.imgur.com/Gd5kOwP.png) + 是否一定要做標準化 (有沒有做有差嗎) 看使用的模型而定 Regression model:一定要做 Tree-based model:沒有太大關係 樹是以數字區間/級距去做分類,有無標準化沒有太大影響 + 常用標準化方法 ![](https://i.imgur.com/fGi5jpo.png) + 特殊狀況 有時候我們不會使用 min/max 方法進行標準化,而會採用 Qlow/Qhigh normalization (如將空間壓縮第一例中的 min 改為 q1, max 改為 q99) + 延伸閱讀 Is it a good practice to always scale/normalize data for machine learning? 資料的標準化對機器學習而言會不會有好的結果 有的時候好,有得時候不好 (但爭議仍在,僅供參考) Good 某些演算法 (如 SVM, DL) 等,對權重敏感或對損失函數平滑程度有幫助者 特徵間的量級差異甚大 Bad 有些指標,如相關不適合在有標準化的空間進行 量的單位在某些特徵上是有意義的 [TOC] ## D15:相關係數實作 Coding 練習日 ### 重點 + 目的? + 用相關係數來迅速找到和預測目標最有線性關係的變數,通常搭配散佈圖來一起了解預測目標與變數的關係 + 使用竅門? + 當Y 不是連續數值時 + 可以將X & Y 軸作轉換,X軸是類別變數,Y軸是連續變數,透過box plot 可看出不同類別值的差異 + 當Y的數值範圍的過大時,可能存在離群值,導致作圖看不出關聯 + 將 Y 做 log scale進行縮放,減小差距 ### 作業 ``` # 將只有兩種值的類別型欄位, 做 Label Encoder, 計算相關係數時讓這些欄位可以被包含在內 from sklearn.preprocessing import LabelEncoder le = LabelEncoder() # 檢查每一個 column for col in app_train: if app_train[col].dtype == 'object': # 如果只有兩種值的類別型欄位 if len(list(app_train[col].unique())) <= 2: # 就做 Label Encoder, 以加入相關係數檢查 app_train[col] = le.fit_transform(app_train[col]) ``` + 為何要將二元值或單一值做 Label Encoder? + 只有兩個值,就表示兩者處於對立面,可視為 Boolean (0/1) ## D16:EDA: 不同數值範圍間的特徵如何檢視/繪圖與樣式Kernel Density ### 重點 + matplotlib 的其他 theme + matplot 不同的theme 可以對應資料形式最比較容易視覺化的呈現 + matplotlib 和 Seaborn 的關係就和 Tenserflow 與 Keras、Pytorch 與 Fast.ai 的關係一模一樣 ![](https://i.imgur.com/ix56ZzK.png) + KDE kenel density estimation + 採用無母數方法畫出一個觀察變數的機率密度函數 + Density plot 需要符合的特性 線下機率為1且對稱 + 常以Gaussion Cosin 作為Kernel function 來estimation + KDE 可以參考這一篇: http://rightthewaygeek.blogspot.com/2015/09/kernel-density-estimation.html $p(x)=\frac{1}{nh}\sum_{i}kernel\frac{x-x_i}{h}$ h是所謂的帶寬,kernel一般而言是以零為中心對稱的函數,並且所有值域的積分必須是1,像是Gaussian function $k(u)=\frac{1}{\sqrt{2\pi}}exp(\frac{u^2}{2})$ 以視覺化的用途我們可以看成: 長條圖轉KDE 就單純類似轉折線圖: 類似discret 轉 continous 的意思 ![](https://i.imgur.com/ZW6XZCN.png) 以KDE將兩筆資料(target 0 ,1)比較 就視覺化來說就比長條圖有感覺了: ![](https://i.imgur.com/dAd1G13.png) ![](https://i.imgur.com/u5oF43y.png) [TOC] ## D17:EDA: 連續型變數離散化 ### 重點 + 一為什麼要離散化 1. 變得更簡單 (可能性變少了) 假設年齡 0-99 (100 種可能性) >> 每 10 歲一組 (10 種可能性) 2. 離散化的變數較穩定,假設年齡 > 30是 1,否則 0 如果沒有離散化,outlier 「年齡 300歲」 會給模型帶來很大的干擾 +Exp. 1.資料組的數量 一樣以年齡為例子,每 10 歲一組就會有 10 組 2.資料組的寬度 一組的寬度是 10 歲 + 二主要的方法 等寬劃分: 按照相同寬度將資料分成幾等份。缺點是受到異常值的影響比較大 等頻劃分: 將資料分成幾等份,每等份資料裡面的個數是一樣的 聚類劃分: 使用聚類演算法將資料聚成幾類,每一個類為一個劃分 主要的方法是等寬劃分 (對應 pandas 中的 cut) 以及等頻劃分 (對應 pandas 中的 qcut) 除了以上的主要方法,也會因需求而需要自己定義離散化的方式,如何離散化是一門學問! + 參考資料 連續特徵的離散化 : 在什麼情況下可以獲得更好的效果(知乎) 連續特徵的離散化:在什麼情況下將連續的特徵離散化之後可以獲得更好的效果? 在工業界,很少直接將連續值作為邏輯回歸模型的特徵輸入,而是將連續特徵離散化為一系列0、1特徵交給邏輯回歸模型,這樣做的優勢有以下幾點: 1. 離散特徵的增加和減少都很容易,易於模型的快速反覆運算; 2. 稀疏向量內積乘法運算速度快,計算結果方便存儲,容易擴展; 3. 離散化後的特徵對異常資料有很強的穩固性:比如一個特徵是年齡>30是1,否則0。 4. 邏輯回歸屬於廣義線性模型,表達能力受限;單變數離散化為N個後,每個變數有單獨 的權重,相當於為模型引入了非線性,能夠提升模型表達能力,加大擬合; 5. 離散化後可以進行特徵交叉,由M+N個變數變為M*N個變數,進一步引入非線性,提升 表達能力; 6. 特徵離散化後,模型會更穩定,比如如果對用戶年齡離散化,20-30作為一個區間,不 會因為一個用戶年齡長了一歲就變成一個完全不同的人。當然處於區間相鄰處的樣本會 剛好相反,所以怎麼劃分區間是門學問; 7. 特徵離散化以後,起到了簡化了邏輯回歸模型的作用,降低了模型過擬合的風險。 李沐曾經說過:模型是使用離散特徵還是連續特徵,其實是一個“海量離散特徵+簡單模型” 同 “少量連續特徵+複雜模型”的權衡。既可以離散化用線性模型,也可以用連續特徵加深度學習。就看是喜歡折騰特徵還是折騰模型了。通常來說,前前者容易,而且可以n個人一起並行做,有成功經驗;後者目前看很贊,能走多遠還須拭目以待。 ## D18:程式實作 把連續型變數離散化 ### 重點 + 把連續型的變數離散化後,可以搭配 pandas 的 groupby 畫出與預測目標的圖 來判斷兩者之間是否有某種關係/趨勢

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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