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.
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
Use the penguins dataset to build a pipeline with KNeighborsClassifier
as the final estimator. Train the pipeline on the dataset and generate predictions for X
.
- Encode the
y
variable. - Create a pipeline containing
ct
,SimpleImputer
,StandardScaler
, andKNeighborsClassifier
. - Use
'most_frequent'
strategy withSimpleInputer
. - Train the
pipe
object using the featuresX
and the targety
.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
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.
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
Use the penguins dataset to build a pipeline with KNeighborsClassifier
as the final estimator. Train the pipeline on the dataset and generate predictions for X
.
- Encode the
y
variable. - Create a pipeline containing
ct
,SimpleImputer
,StandardScaler
, andKNeighborsClassifier
. - Use
'most_frequent'
strategy withSimpleInputer
. - Train the
pipe
object using the featuresX
and the targety
.
Solution
Thanks for your feedback!
single