Preprocessing within a pipeline
Now that you've seen what steps need to be taken individually to properly process the Ames housing data, let's use the much cleaner and more succinct DictVectorizer approach and put it alongside an XGBoostRegressor inside of a scikit-learn pipeline.
Questo esercizio fa parte del corso
Extreme Gradient Boosting with XGBoost
Istruzioni dell'esercizio
- Import
DictVectorizerfromsklearn.feature_extractionandPipelinefromsklearn.pipeline. - Fill in any missing values in the
LotFrontagecolumn ofXwith0. - Complete the steps of the pipeline with
DictVectorizer(sparse=False)for"ohe_onestep"andxgb.XGBRegressor()for"xgb_model". - Create the pipeline using
Pipeline()andsteps. - Fit the
Pipeline. Don't forget to convertXinto a format thatDictVectorizerunderstands by calling theto_dict("records")method onX.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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
____