scikit-learn interview question
How do you handle categorical features in scikit-learn?
How you'd do it Asked in Machine Learning Engineer interviews
Summary
Use OneHotEncoder(handle_unknown="ignore") for low-cardinality categories with linear models, OrdinalEncoder for
ordered categories or tree models, TargetEncoder (scikit-learn 1.3+, cross-fitted internally) for
high-cardinality columns, and HistGradientBoosting* with categorical_features for native support.
Keep reading with a membership
The full answer with examples, key points and comparisons is part of the membership, along with every other interview answer, progress tracking and Daily Review. Most-asked answers stay free to read.
More scikit-learn questions
- How do scikit-learn Pipelines and ColumnTransformer work, and why use them?
- What do fit, transform, fit_transform and predict do in scikit-learn?
- How do you tune hyperparameters with GridSearchCV or RandomizedSearchCV?
- Your scikit-learn model's cross-validation score varies a lot between folds. What does it mean, and what do you do?