填補連續型遺漏值

Feature Engineering for Machine Learning in Python

Robert O'Callaghan

Director of Data Science, Ordergroove

刪除遺漏值

  • 測試集含遺漏值時,不能直接刪除整列
Feature Engineering for Machine Learning in Python

還能怎麼做?

  • 類別欄:以最常見值取代,或用標示遺漏的字串(如「None」)
  • 數值欄:以合適的數值取代
Feature Engineering for Machine Learning in Python

集中趨勢量數

  • 平均數(mean)
  • 中位數(median)
Feature Engineering for Machine Learning in Python

計算集中趨勢量數

print(df['ConvertedSalary'].mean())
print(df['ConvertedSalary'].median())
92565.16992481203
55562.0
Feature Engineering for Machine Learning in Python

填補遺漏值

df['ConvertedSalary'] = df['ConvertedSalary'].fillna(
    df['ConvertedSalary'].mean()
)
df['ConvertedSalary'] = df['ConvertedSalary']\
                         .astype('int64')
Feature Engineering for Machine Learning in Python

四捨五入

df['ConvertedSalary'] = df['ConvertedSalary'].fillna(
    round(df['ConvertedSalary'].mean())
)
Feature Engineering for Machine Learning in Python

一起來練習吧!

Feature Engineering for Machine Learning in Python

Preparing Video For Download...