始める無料で始める

腎疾患ケーススタディ II: Feature Union

数値列とカテゴリ列をそれぞれ個別に補完できたので、次は scikit-learn の FeatureUnion を使って、それぞれの結果を結合します。結果は 2 つの別々の変換器オブジェクト numeric_imputation_mappercategorical_imputation_mapper に入っています。

FeatureUnion には、すでに Machine Learning with the Experts: School Budgets で触れているかもしれません。パイプラインと同様に、(string, transformer) のタプルのリストを渡します。各タプルの前半は変換器の名前です。

この演習はコースの一部です

XGBoost で学ぶ極限の勾配ブースティング

コースを見る

演習の手順

  • sklearn.pipeline から FeatureUnion をインポートします。
  • FeatureUnion() を使って、numeric_imputation_mappercategorical_imputation_mapper の結果を結合し、それぞれの名前を "num_mapper""cat_mapper" とします。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Import FeatureUnion
from sklearn.pipeline import FeatureUnion

# Combine the numeric and categorical transformations
numeric_categorical_union = ____([
                                          ("____", ____),
                                          ("____", ____)
                                         ])
コードを編集して実行