开始使用免费开始使用

肾病案例研究 II:特征联合(Feature Union)

在分别对数值列和分类列进行了缺失值填补之后,您的任务是使用 scikit-learn 的 FeatureUnion 将它们的结果拼接起来。这两个结果分别包含在两个独立的转换器对象中——numeric_imputation_mappercategorical_imputation_mapper

您可能已经在课程 Machine Learning with the Experts: School Budgets 中见过 FeatureUnion。与管道(pipeline)类似,您需要向它传入一个由 (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 = ____([
                                          ("____", ____),
                                          ("____", ____)
                                         ])
编辑并运行代码