欠損値への対処(I)

Python で学ぶ Machine Learning のための特徴量エンジニアリング

Robert O'Callaghan

Director of Data Science, Ordergroove

リストワイズ削除

      SurveyDate      ConvertedSalary     Hobby ... \
0  2/28/18 20:20                  NaN       Yes ...
1  6/28/18 13:26              70841.0       Yes ...
2    6/6/18 3:37                  NaN        No ...
3    5/9/18 1:06              21426.0       Yes ...
4  4/12/18 22:41              41671.0       Yes ...
Python で学ぶ Machine Learning のための特徴量エンジニアリング

Pythonでのリストワイズ削除

# いずれかの欠損を含む行をすべて削除
df.dropna(how='any')
Python で学ぶ Machine Learning のための特徴量エンジニアリング

Pythonでのリストワイズ削除

# 特定列で欠損のある行を削除
df.dropna(subset=['VersionControl'])
Python で学ぶ Machine Learning のための特徴量エンジニアリング

削除の問題点

  • 有効なデータも削除する
  • 無作為性に依存する
  • 情報量が減る
Python で学ぶ Machine Learning のための特徴量エンジニアリング

文字列での置換

# 特定の列の欠損値を
# 文字列で置換
df['VersionControl'].fillna(
    value='None Given', inplace=True
)
Python で学ぶ Machine Learning のための特徴量エンジニアリング

欠損の記録

# 欠損でない位置を記録
df['SalaryGiven'] = df['ConvertedSalary'].notnull()
# 特定の列を削除
df.drop(columns=['ConvertedSalary'])
Python で学ぶ Machine Learning のための特徴量エンジニアリング

Practice time

Python で学ぶ Machine Learning のための特徴量エンジニアリング

Preparing Video For Download...