Challenge: Creating a Complete ML Pipeline
Now create a pipeline that includes a final estimator. This produces a trained prediction pipeline that can generate predictions for new instances using the .predict() method.
Since a predictor requires the target variable y, encode it separately from the pipeline built for X. Use LabelEncoder to encode the target.
Additionally, there are materials to review the syntax of make_column_transformer and make_pipeline.
Since the predictions are encoded as 0, 1, or 2, the .inverse_transform() method of LabelEncoder can be used to convert them back to the original labels: 'Adelie', 'Chinstrap', or 'Gentoo'.
Swipe to start coding
You have a penguin DataFrame df. Build and train a full ML pipeline using KNeighborsClassifier.
- Encode the target
ywithLabelEncoder. - Create a
ColumnTransformer(ct) that appliesOneHotEncoderto'island'and'sex', withremainder='passthrough'. - Build a pipeline with:
β’
ctβ’SimpleImputer(strategy='most_frequent')β’StandardScalerβ’KNeighborsClassifier - Fit the pipeline on
Xandy. - Predict on
Xand print the first decoded class names.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you show me an example of how to use LabelEncoder with the target variable?
How do I combine the column transformer and the final estimator in a pipeline?
What is the difference between make_column_transformer and make_pipeline?
Awesome!
Completion rate improved to 3.13
Challenge: Creating a Complete ML Pipeline
Swipe to show menu
Now create a pipeline that includes a final estimator. This produces a trained prediction pipeline that can generate predictions for new instances using the .predict() method.
Since a predictor requires the target variable y, encode it separately from the pipeline built for X. Use LabelEncoder to encode the target.
Additionally, there are materials to review the syntax of make_column_transformer and make_pipeline.
Since the predictions are encoded as 0, 1, or 2, the .inverse_transform() method of LabelEncoder can be used to convert them back to the original labels: 'Adelie', 'Chinstrap', or 'Gentoo'.
Swipe to start coding
You have a penguin DataFrame df. Build and train a full ML pipeline using KNeighborsClassifier.
- Encode the target
ywithLabelEncoder. - Create a
ColumnTransformer(ct) that appliesOneHotEncoderto'island'and'sex', withremainder='passthrough'. - Build a pipeline with:
β’
ctβ’SimpleImputer(strategy='most_frequent')β’StandardScalerβ’KNeighborsClassifier - Fit the pipeline on
Xandy. - Predict on
Xand print the first decoded class names.
Solution
Thanks for your feedback!
single