Interview Q&A · questions with model answers
scikit-learn Interview Questions
Part of the study plan for: Machine Learning Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked How do scikit-learn Pipelines and ColumnTransformer work, and why use them?
A Pipeline chains transformers and a final estimator so fit runs every step in order on the training data and predict applies the same fitted steps to new data. ColumnTransformer applies different…
-
What do fit, transform, fit_transform and predict do in scikit-learn?
fit learns from data (a scaler learns means, a model learns weights). transform applies what was learned to data. fit_transform does both on the same data (training data only). predict (and…
-
How do you tune hyperparameters with GridSearchCV or RandomizedSearchCV?
Wrap the pipeline in a search object with a parameter grid or distributions, a cross-validation scheme and a scoring metric, fit it on the training data, then inspect best_params_ and cv_results_…
-
How do you handle categorical features in scikit-learn?
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…
-
Your scikit-learn model's cross-validation score varies a lot between folds. What does it mean, and what do you do?
High variance across folds means the estimate is unreliable: the dataset may be small, folds may differ in class balance or groups, there may be outliers or time effects, or the model itself is…