CAB212 · Unit 1: Machine learning foundations
Feature scaling, encoding and handling missing data
8 practice questions
Key points
- Scale for distance- and gradient-based models
- Min-max -> [0,1]; z-score -> mean 0, sd 1
- One-hot for nominal categories
- Median imputation resists outliers
Scaling puts features on comparable ranges. It matters for distance-based and gradient-based models (k-NN, SVM, k-means, logistic regression, neural networks) but not for tree-based models.
- Min-max: x' = (x - min) / (max - min), range [0, 1].
- Standardization (z-score): x' = (x - mean) / std, mean 0 and standard deviation 1.
Encoding categorical data: one-hot encoding makes a binary column per category (no false ordering); ordinal/label encoding maps categories to integers (only for truly ordered categories).
Missing values: drop rows/columns, or impute with mean/median (numeric) or mode (categorical). Median is robust to outliers. Impute using training-set statistics only.
Worked example: values [10, 20, 30]: min-max of 20 = (20-10)/(30-10) = 0.5.
Exam pitfall: label-encoding a nominal feature as integers 1, 2, 3 wrongly implies order and distance; use one-hot encoding instead.
Try two questions
Which imputation is most robust for a skewed numeric feature with outliers?
- Maximum
- Zero always
- Median
- Mean
Show the answer
C. The median is not pulled by extreme values.
Why is feature scaling important for k-NN?
- k-NN is trained with gradient descent
- k-NN cannot take numeric input at all
- Scaling increases the number of neighbours used
- Distance is dominated by features with large ranges
Show the answer
D. Unscaled large-range features dominate Euclidean distance.