肾病案例研究 II:特征联合(Feature Union)
在分别对数值列和分类列进行了缺失值填补之后,您的任务是使用 scikit-learn 的 FeatureUnion 将它们的结果拼接起来。这两个结果分别包含在两个独立的转换器对象中——numeric_imputation_mapper 和 categorical_imputation_mapper。
您可能已经在课程 Machine Learning with the Experts: School Budgets 中见过 FeatureUnion。与管道(pipeline)类似,您需要向它传入一个由 (string, transformer) 形式的元组组成的列表,其中每个元组的前半部分是转换器的名称。
本练习是课程的一部分
使用 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 = ____([
("____", ____),
("____", ____)
])