single
Challenge: Creating a Complete ML Pipeline
Sveip for å vise menyen
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'.
Sveip for å begynne å kode
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.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår