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
    # Day 22 -25 ###### tags: `cupoy`, `ML100` :::info + [Teams 會議連結](https://teams.live.com/meet/9560507323678) + 2022-03-03 19:30 + ## ::: [TOC] ## D22:特徵工程簡介 > 資料和特徵決定了機器學習的上限,而模型和演算法只是逼近這個上限而已。 > ——特徵工程 ### 重點 + 最大限度的從原始資料中提取有價值的資訊(特徵) + 減少不重要/不應該的東西 + 資料清理 + 離群值處理 + ...(詳細見前面關於前處理的部分) + 增加重要/應該的東西 + 基於事實的特徵轉換 + 標記Label其實也應該算是一種 + 基於數值的特徵轉換 + 標準化、區間縮放 + 二值化(連續數值->離散類別) + 補充:特徵重要性評估 + 通常發生在模型後的部分 + 可以再用來迭代調整前面的模型 ### 用法整理 Label和Scale相關的之前清理已經有過就先跳過 補充一下特徵重要性評估的用法 {%gist Keycatowo/eb042f1fdd5dd323e0a81a0670249bfb %} 欄位名稱: ![image](https://user-images.githubusercontent.com/47293699/156539912-61ef5b11-e96a-45ac-9f66-eccd289b33d5.png) 重要程度: ![image](https://user-images.githubusercontent.com/47293699/156539953-44fba811-1b07-4322-9fb2-afcf91efe30a.png) print出來顯示 ![image](https://user-images.githubusercontent.com/47293699/156540009-fa89a53e-7e4c-4c7e-9ff1-e2daca1aaaa7.png) 圖形顯示 ![image](https://user-images.githubusercontent.com/47293699/156540048-2d414baa-d525-4bd6-905b-1bb0e2d89c9e.png) ### 補充:案例分享 親權判決預測案例 + 原本採用對申請雙方有利不利的各13項onehot內容作為輸入($2*2*13=52$) + 套用一個簡單的公式進行轉化 + $$S = \frac{A+C-B-D}{2}$$ + 出來的數值範圍為-1~1,一定程度上可以表示該項目的傾向,也方便後續分析 + 模型穩定性和準確度基本上都提升許多 + 在這種資料量有限的實際案例中特別有效果 ### 延伸閱讀 [以為是哈士奇分類器,其實是...](https://www.researchgate.net/figure/A-husky-on-the-left-is-confused-with-a-wolf-because-the-pixels-on-the-right_fig1_329277474) ## D24:類別型特徵 - 基礎處理 ![](https://i.imgur.com/wcmB6cz.png) ### 重點 + 類別型特徵有哪兩種基礎編碼方式 + Label encoding (標籤編碼) ![](https://i.imgur.com/Y9HHHuC.png) + One hot encoding (獨熱編碼) ![](https://i.imgur.com/WdbiqjJ.png) + 兩種基礎編碼方式中,哪一種比較常用? 為什麼? + 非深度學習: Label Encoding + 深度學習: one hot encoding + Example ``` import numpy as np import pandas as pd country=['Taiwan','Australia','Ireland','Australia','Ireland','Taiwan'] age=[25,30,45,35,22,36] salary=[20000,32000,59000,60000,43000,52000] dic={'Country':country,'Age':age,'Salary':salary} data=pd.DataFrame(dic) data ``` ![](https://i.imgur.com/npKKGBB.png) ``` from sklearn.preprocessing import LabelEncoder labelencoder = LabelEncoder() data_le=pd.DataFrame(dic) data_le['Country'] = labelencoder.fit_transform(data['Country']) data_le ``` ![](https://i.imgur.com/QjDVN4I.png) ``` data_dum = pd.get_dummies(data) pd.DataFrame(data_dum) ``` ![](https://i.imgur.com/BJgwD9Y.png) ## D23:數值型特徵 - 去除偏態 ![](https://i.imgur.com/wcmB6cz.png) ### 重點 + 主要是針對數值型的特徵資料做操作 + 時機:資料彙整後 模型選擇建立之前 + 老師要當掉多少人(希望當掉的同學不要太多( 讓大部分同學都過 )) ![](https://i.imgur.com/KKEVutN.png) 1)標準化(平移)高低分群體還是分得太明顯,不好看 ![](https://i.imgur.com/dXcOYvo.png) 2)去離群值 高分群的努力都白費了,不公平 ![](https://i.imgur.com/WPr8coO.png 3)去除偏態 開根號乘以 10 ![](https://i.imgur.com/VeT1T8j.png) + 結論 1)感覺上 : 考試成績分布越集中在中央,似乎越理想 2)其實我們所謂的感覺更合理,意思就是越接近常態分布 3)去除偏態的目標在於讓數值更接近常態分布(左右對稱,集中點在中央),讓平均值更具有代表性 + 平均值更具有代表性又是什麼意思 ![](https://i.imgur.com/7bZ0NGX.png) 例 : 台灣整體薪資分布 圖源 : 行政院主計處 1)平均值(紅線處) 不具有代表性 2)中位數(D5線) 反而較具代表性 3)薪資分布中,高薪群的長尾分布造成平均值不具代表性 4)但是對數去偏後的新分布,平均值就比較具有代表性 + 複習 : 對數去偏(log1p) ![](https://i.imgur.com/9H5FtW3.png) 1)對數去偏就是使用自然對數去除偏態 2)常見於計數 / 價格這類非負且可能為 0 的欄位 3)因為需要將 0 對應到 0,所以先加一 (plus one) 再取對數 (log) 平均值就相當有意義了 5)還原時使用 expm1,也就是先取指數 (exp) 後再減一 (minus one) + 方根去偏(sqrt) -方根去偏(sqrt) 就是將數值減去最小值後開根號, 最大值有限時適用 (例 : 成績轉換) ![](https://i.imgur.com/wqF3YNA.png) + 分布去偏(boxcox) 1)是採用boxcox轉換函數(詳見下表), 將數值丟進去boxcox轉換函數 得到新的分布 3)函數的 lambda(λ) 參數為 0 時等於 log 函數, 4)lambda(λ) 為 0.5 時等於開根號 (即sqrt), 5)因此可藉由參數的調整更靈活地轉換數值, 但要特別注意Y的輸入數值必須要為正 (必須大於0) ![](https://i.imgur.com/ztSZAgd.png) 6)boxcox定義 ![](https://i.imgur.com/OoJP4bB.png) 1)藉由指定入 就有不同的轉換型是 2)入=0 對數型式轉換 3)入不=0 依入不同 有不同型式的轉換 4) ## D25:類別型特徵 - 均值編 ![](https://i.imgur.com/wcmB6cz.png) ### 重點

    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