single
Challenge: Creating a Complete ML Pipeline
Deslize para mostrar o 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'.
Deslize para começar 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.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo