P
📊Analyse de donnéesBeginnerAll AIs

Encode categorical variables

Encode categorical features

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Write Python code using scikit-learn to encode the categorical columns in DataFrame df. Use one-hot encoding for [low cardinality columns], target encoding for [high cardinality columns], and ordinal encoding for [ordered columns]. Wrap everything in a ColumnTransformer that can be used in a Pipeline.

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Use Cases

Encode categorical features

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Utilise `OneHotEncoder(handle_unknown='ignore')` pour gérer les catégories inédites, et spécifie l’ordre des catégories dans `OrdinalEncoder(categories=...)`. Pour le target encoding, veille à ne l’entraîner que sur le fold d’entraînement – l’intégrer dans un `Pipeline` avec `cross_val_score` évite les fuites de données.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

Build a recommendation system

Build recommendation systems

0106

Create an automated EDA report

Generate EDA reports automatically

0101
📊Analyse de donnéesIntermediateAll AIs

Build a feature engineering pipeline

Create reproducible preprocessing pipelines

0104
📊Analyse de donnéesIntermediateAll AIs

Statistical Power Analysis

Planning a statistical experiment

0122