PySpark로 하는 Feature Engineering
John Hogue
Lead Data Scientist, General Mills
데이터 수집
데이터 저장 규칙
이기종 데이터 결합
의도적 결측

완전 무작위 결측(MCAR)
무작위 결측(MAR)
비무작위 결측(MNAR)
결측 데이터가 있는 행을 언제 삭제할까요?
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로 하는 Feature Engineering