single
Challenge: Creating a Complete ML Pipeline
Desliza para mostrar el menú
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'.
Desliza para comenzar a programar
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.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla