iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 13
0
Google Developers Machine Learning

Machine Learning Day30系列 第 15

[Day15] 特徵工程-資料類型處理

  • 分享至 

  • twitterImage
  •  

特徵工程的資料類型有包含三種,
數值型、類別型、時間型,
需要進行填補空值、特徵處理等,
以下來源參考機器學習百日馬拉松。

數值型

數值型資料,除了填補缺值和去除離群值外,主要進行「去偏態」,
讓原本左偏或右偏的資料可以符合「常態假設」。

1.對數去偏(log1p)

對數去偏就是使用「自然對數」去除偏態,
常見於計數、價格這類非負且可能為 0 的欄位。

df_fixed['LotArea'] = np.log1p(df_fixed['LotArea'])

2.⽅根去偏(sqrt)

將數值減去最小值後開根號,最大值有限制適用,
通常用於成績轉換。

df_fixed['LotArea'] = stats.boxcox(df['LotArea'])[0]

3.分布去偏(boxcox)

採⽤boxcox轉換函數,需代入函數的 lambda(λ) 參數。

df_fixed['LotArea'] = stats.boxcox(df['LotArea'], lmbda=0.5)

類別型

1. 標籤編碼 (Label Encoding)

類似於流⽔水號,
依序將新出現的類別依序編上新代碼。

https://ithelp.ithome.com.tw/upload/images/20190930/20112568BOq3LwclcX.png

2. 獨熱編碼 (One Hot Encoding)

為了改良數字⼤小沒有意義的問題,
將不同的類別分別獨立為⼀欄。

https://ithelp.ithome.com.tw/upload/images/20190930/20112568U3BH0rOAlG.png

3. 均值編碼 (Mean Encoding)

取用兩個相關欄位,使⽤目標值的平均值,取代原本的類別型特徵。
https://ithelp.ithome.com.tw/upload/images/20190930/20112568qsCVEoHpBi.png

4. 計數編碼 (Counting)

類別的⽬標均價與類別筆數呈正相關(或負相關),也可以將筆數本⾝身當成特徵。

https://ithelp.ithome.com.tw/upload/images/20190930/20112568qaIj8ADZnN.png

5. 特徵雜湊 (Feature Hash)

將類別由雜湊函數定應到⼀組數字,需調整雜湊函數對應值的數量。

https://ithelp.ithome.com.tw/upload/images/20190930/2011256835NCmyAL9r.png

時間型

1. 時間特徵分解

最直覺的⽅式,就是依照原意義分欄處理,或加上第幾周或星期幾。
https://ithelp.ithome.com.tw/upload/images/20190930/20112568XjDBJOBdtB.png

2. 週期循環特徵

時間也有週期的概念,可以用週期合成一些重要的特徵。

https://ithelp.ithome.com.tw/upload/images/20190930/20112568eK1A3l7n4D.png


除了針對不同資料類型做不同處理,
後續還有特徵組合、特徵篩選和特徵評估,
來提昇機器學習的準確率和效率。


以上,打完收工。


上一篇
[Day14] 數據前處理EDA
下一篇
[Day16] 特徵工程-處理方法
系列文
Machine Learning Day3026
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言