在流水线中进行预处理
既然您已经了解了针对 Ames 房价数据需要分别进行哪些处理步骤,现在就来使用更简洁清晰的 DictVectorizer 方法,并将其与 XGBoostRegressor 一起放入 scikit-learn 的流水线中。
本练习是课程的一部分
使用 XGBoost 的极端梯度提升
练习说明
- 从
sklearn.feature_extraction导入DictVectorizer,从sklearn.pipeline导入Pipeline。 - 将
X中LotFrontage列的缺失值填充为0。 - 使用
DictVectorizer(sparse=False)作为"ohe_onestep",以及xgb.XGBRegressor()作为"xgb_model",补全流水线的步骤。 - 使用
Pipeline()和steps创建流水线。 - 拟合该
Pipeline。别忘了在调用X的to_dict("records")方法后,再将其传入,以转换为DictVectorizer可理解的格式。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import necessary modules
____
____
# Fill LotFrontage missing values with 0
X.LotFrontage = ____
# Setup the pipeline steps: steps
steps = [("ohe_onestep", ____),
("xgb_model", ____)]
# Create the pipeline: xgb_pipeline
xgb_pipeline = ____
# Fit the pipeline
____