【Kaggle】Learn Feature Engineering①
Learn Feature Engineering Tutorials | Kaggle
kaggle learn で feature engineeringを勉強するシリーズ第一弾
1) Construct features from timestamps
.dt.hour.astype('uint8')を使うと、pandas形式のタイムスタンプを時間(hour)の特徴量に変換することができる。
# Split up the times
click_times = click_data['click_time']
clicks['day'] = click_times.dt.day.astype('uint8')
clicks['hour'] = click_times.dt.hour.astype('uint8')
clicks['minute'] = click_times.dt.minute.astype('uint8')
clicks['second'] = click_times.dt.second.astype('uint8')
2) Label Encoding
scikit-learnのpreprocessing.LabelEncoderから、.fit_transform methodを使うと、categorical featureをlabel encodingすることができる。
label_encoder = preprocessing.LabelEncoder()
for feature in cat_features:
encoded = label_encoder.fit_transform(clicks[feature])
clicks[feature + '_labels'] = encoded
どちらも知らなかったのでとても勉強になりました。