PySparkで学ぶ特徴量エンジニアリング
John Hogue
Lead Data Scientist, General Mills
ランダムフォレスト回帰

経済
行政
社会
季節
時系列特徴
率・比率・合計
拡張特徴
# データの形状は?
print((df.count(), len(df.columns)))
(5000, 126)
from pyspark.ml.feature import VectorAssembler
# 欠損値を置換
df = df.fillna(-1)
# ベクトル化する列を定義
features_cols = list(df.columns)
# 目的変数を一覧から除外
features_cols.remove('SALESCLOSEPRICE')
# ベクトルアセンブラーを作成 vec = VectorAssembler(inputCols=features_cols, outputCol='features')# データに適用 df = vec.transform(df)# 特徴ベクトルと目的変数のみ選択 ml_ready_df = df.select(['SALESCLOSEPRICE', 'features'])# 結果を確認 ml_ready_df.show(5)
+----------------+--------------------+
| SALESCLOSEPRICE| features|
+----------------+--------------------+
|143000 |(125,[0,1,2,3,5,6...|
|190000 |(125,[0,1,2,3,5,6...|
|225000 |(125,[0,1,2,3,5,6...|
|265000 |(125,[0,1,2,3,4,5...|
|249900 |(125,[0,1,2,3,4,5...|
+----------------+--------------------+
only showing top 5 rows
PySparkで学ぶ特徴量エンジニアリング