PySparkで学ぶ特徴量エンジニアリング
John Hogue
Lead Data Scientist, General Mills
データ収集
データ保存ルール
異種データの結合
意図的な欠損

完全ランダム欠損
ランダム欠損
非ランダム欠損
欠損データのある行を削除するタイミング
isNull()
df.where(df['ROOF'].isNull()).count()
765
# Import library import seaborn as sns# subset the dataframe sub_df = df.select(['ROOMAREA1'])# sample the dataframe sample_df = sub_df.sample(False, .5, 4)# Convert to Pandas DataFrame pandas_df = sample_df.toPandas()# Plot it sns.heatmap(data=pandas_df.isnull())

欠損値を置換するプロセス
ルールベース
統計ベース
モデルベース
** fillna(value, subset=None)
value 欠損値に代入する値subset 対象とする列名のリスト# Replacing missing values with zero
df.fillna(0, subset=['DAYSONMARKET'])
# Replacing with the mean value for that column
col_mean = df.agg({'DAYSONMARKET': 'mean'}).collect()[0][0]
df.fillna(col_mean, subset=['DAYSONMARKET'])
PySparkで学ぶ特徴量エンジニアリング