Feature Engineering với PySpark
John Hogue
Lead Data Scientist, General Mills
Thu thập dữ liệu
Quy tắc lưu trữ dữ liệu
Nối dữ liệu rời rạc
Cố ý để trống

Thiếu hoàn toàn ngẫu nhiên
Thiếu ngẫu nhiên
Thiếu không ngẫu nhiên
Khi nào nên loại bỏ các dòng có dữ liệu thiếu?
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())

Quy trình thay thế giá trị thiếu
Dựa trên quy tắc
Dựa trên thống kê
Dựa trên mô hình
** fillna(value, subset=None)
value giá trị dùng để thay thế phần thiếusubset danh sách cột cần thay thế phần thiếu# Thay giá trị thiếu bằng 0
df.fillna(0, subset=['DAYSONMARKET'])
# Thay bằng giá trị mean của cột đó
col_mean = df.agg({'DAYSONMARKET': 'mean'}).collect()[0][0]
df.fillna(col_mean, subset=['DAYSONMARKET'])
Feature Engineering với PySpark