腎臟疾病個案研究 II:Feature Union
在已經分別對數值與類別欄位進行插補之後,你現在的任務是使用 scikit-learn 的 FeatureUnion 將兩者的結果串接起來。這兩個結果分別包含在兩個轉換器物件中——numeric_imputation_mapper 與 categorical_imputation_mapper。
你可能已在 Machine Learning with the Experts: School Budgets 看過 FeatureUnion。和 pipeline 一樣,你需要傳入一個由 (string, transformer) tuple 組成的清單,其中每個 tuple 的前半部是轉換器的名稱。
本練習屬於課程
使用 XGBoost 的極端梯度提升
練習說明
- 從
sklearn.pipeline匯入FeatureUnion。 - 使用
FeatureUnion()結合numeric_imputation_mapper與categorical_imputation_mapper的結果,並分別命名為"num_mapper"與"cat_mapper"。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import FeatureUnion
from sklearn.pipeline import FeatureUnion
# Combine the numeric and categorical transformations
numeric_categorical_union = ____([
("____", ____),
("____", ____)
])