MST0052 · Lecture 3 · Fall 2026
No dataset yet? Talk to me after class, or revisit the dataset pointers from L1.
01
One column per category, 0 or 1
k-NN, logistic regression, PCA, k-means — scaling decides what they see.
Indifferent to scale. Still need encoding for string columns.
02
Wrong — the scaler sees the test set
Right — split first, pipeline
Same bug, different channel
fit only ever sees training data — guaranteed by construction.
fit
03
Preprocessing + model · one object
Learn parameters — mean, std, categories.
Apply the learned parameters.
Both at once — training only.
The diagram, in code
Everything · one object
Reference — screenshot this
04
Predict survival · the L2 pattern, now with real mess
Step 1 · Load & inspect
Step 1 · The missing-data picture
Keep pclass sex age fare embarked — drop deck (77% missing)
pclass
sex
age
fare
embarked
deck
Step 2 · Split before anything fits
stratify=y keeps the survival ratio balanced in both sets.
stratify=y
Step 3 · Preprocessor + model
Step 4 · Fit & evaluate
Step 5 · Cross-validate
CV on the training set — the test set stays untouched. The L2 pattern.
05
FunctionTransformer · log inside the pipeline
06
Nominal categories, no order — colour, city, sex.
Ordered categories — low/medium/high, education level.
Watch out: one-hot on a 500-category column creates 500 columns. Group rare categories, or consider target encoding.
Most project datasets are MCAR or MAR. Suspect MNAR? Discuss it in your report.
Same pattern · regression target
Debugging · what does the model actually see?