Encoding categoricals, scaling, binning, interaction features, date features, text features, imputation and leakage avoidance.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is one-hot encoding used for?
Show answer
Converts categorical variables into binary columns, one per category, with a single 1 and rest 0s.
- When is label encoding preferred over one-hot encoding?
Show answer
When the categorical variable is ordinal (has natural ordering) and you want fewer features.
- What is ordinal encoding?
Show answer
Assigns integers to categories based on their natural order, e.g. low=1, medium=2, high=3.
- Define target encoding in feature engineering.
Show answer
Replaces each category with the mean (or median) of the target variable for that category.
- What is binary encoding?
Show answer
Converts categories to binary numbers, then splits the binary digits into separate features, reducing dimensionality compared to one-hot.
- What is frequency encoding?
Show answer
Replaces each category with how often it appears in the dataset.
- When might one-hot encoding cause problems?
Show answer
With high-cardinality features (many unique categories), creating too many columns.
- What is the dummy variable trap?
Show answer
When using one-hot encoding, including all dummy columns (not dropping one) leads to multicollinearity in linear models.
- Define standardization (z-score normalization).
Show answer
Subtracts the mean and divides by standard deviation: (x - mean) / std. Result has mean 0 and std 1.
- Define min-max normalization.
Show answer
Scales features to a fixed range, usually [0,1], using (x - min) / (max - min).
- What is robust scaling?
Show answer
Uses median and interquartile range instead of mean and std, making it less sensitive to outliers.
- When should you NOT scale a feature?
Show answer
Tree-based models (decision trees, random forests) are scale-invariant, so scaling is unnecessary.
- What is log scaling used for?
Show answer
Compresses the range of large values, useful for right-skewed distributions.
- Why is it important to fit scalers on training data only?
Show answer
To prevent leakage, the scaler parameters (mean, std, min, max) must be computed from training data before applying to test data.
- What is equal-width binning?
Show answer
Divides the range into n intervals of equal width, then assigns values to bins.