開始使用免費開始

腎臟疾病個案研究 II:Feature Union

在已經分別對數值與類別欄位進行插補之後,你現在的任務是使用 scikit-learn 的 FeatureUnion 將兩者的結果串接起來。這兩個結果分別包含在兩個轉換器物件中——numeric_imputation_mappercategorical_imputation_mapper

你可能已在 Machine Learning with the Experts: School Budgets 看過 FeatureUnion。和 pipeline 一樣,你需要傳入一個由 (string, transformer) tuple 組成的清單,其中每個 tuple 的前半部是轉換器的名稱。

本練習屬於課程

使用 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 = ____([
                                          ("____", ____),
                                          ("____", ____)
                                         ])
編輯並執行程式碼