Data processing and features practice problems
29 problems · 0 solved
Before any model can learn, raw data has to be cleaned, split and turned into numbers. Most real model failures come from this stage, especially data leakage, where information from the test set sneaks into training. Think of it as preparing ingredients before cooking: bad prep spoils the dish no matter how good the recipe is. These problems focus on doing this prep correctly. You will standardise features without leaking test data, scale with the median and IQR to resist outliers, compute balanced class weights, use the hashing trick for categories, bin features into quantile buckets learned on training data, generate K-fold and stratified splits, split folds by user so no user lands in both sets, remove duplicate texts after normalising them, target-encode a category with smoothing, and fit a full imputation, scaling and one-hot pipeline. Start with the Easy problems on standardisation and class weights. Then do the splitting problems, and finish with grouped folds, target encoding and the full pipeline. Interviewers love leakage questions, and in real jobs careful splits and features often matter more than the choice of model.
Easy 14
- Standardise features without leaking test data
- Scale features with the median and IQR so outliers do not dominate
- Encode hour of day and day of week as sine and cosine features
- Clip outliers using percentiles learned on the training set only
- Turn categorical tokens into a fixed-size vector with the hashing trick
- Compute balanced class weights for an imbalanced dataset
- Fit a min-max scaler on train and apply it to test
- Ordinal-encode a category column and map unseen values to -1
- Impute missing values with train medians and add missing-indicator columns
- Cap outliers with IQR fences learned from training data
- Bin a feature into equal-width buckets learned on train
- Find test rows that also appear in the training set
- Build stratified K-fold validation folds by dealing each class round-robin
- Expand features into degree-2 polynomial and interaction terms
Medium 9
- Split a dataset so every class keeps its share
- Bin a feature into quantile buckets learned from training data
- Frequency-encode a category with a shared bucket for rare and unseen values
- Generate K-fold train and validation index splits
- Remove duplicate training texts after normalising them
- One-hot encode with an 'other' column for rare and unseen categories
- Flag outliers with the modified z-score based on the median
- Apply the Yeo-Johnson power transform for a given lambda
- Extract hour, weekday and cyclic time features from Unix timestamps
Hard 6
- Target-encode a category with smoothingPro
- Fit imputation, scaling and one-hot encoding on train and apply them to testPro
- Estimate Jaccard similarity between documents with MinHash signaturesPro
- Split folds by user so no user lands in both train and validationPro
- Fill missing values from the k nearest rows (KNN imputation)Pro
- Choose the Box-Cox lambda by maximum likelihood over a gridPro