MST0052 · Lecture 5 · Fall 2026
Recap · Lecture 4
01
A continuous number — price, temperature.
A category — churn, spam, malignant.
"This customer will churn."
"This customer has a 73% chance of churning."
02
After standardisation, one unit means one training-set standard deviation.
Equivalent to maximising the likelihood of the observed labels.
Baseline · same pipeline as L4
predict_proba is the output you evaluate with.
predict_proba
03
Memorises — follows noise. High variance.
Blurs — misses local patterns. High bias.
Learn each mean and scale on the training fold only — keep the scaler in the pipeline.
P(class 1) = 1/3 = 33% → class 0
P(class 1) = 10/14.5 = 69% → class 1
Tune k · same GridSearchCV as L4
Distances dominate by scale — StandardScaler is mandatory.
StandardScaler
Vocabulary: great · fun · slow · boring — every other word is ignored
"Great film, so much fun"
"Great cast, great script"
"A bit slow at first, but great fun — never boring"
"Boring and slow"
"Boring plot, boring cast"
"Great trailer, but slow and boring — not fun"
prior × great × fun × slow
A word never seen in a class has count 0 — and zeroes the whole product. The fix: add 1 to every count (alpha=1).
alpha=1
A bell curve within each class; features are assumed independent given the class.
Normalising makes the probabilities sum to 1; it does not guarantee calibration.
Fast baseline · defaults first
For text features such as word counts or TF-IDF, use MultinomialNB.
MultinomialNB
Search · memorise · count
Does the model grow with the data?
A fixed form — the same number of parameters however much data you add.
Logistic regression · naive Bayes · L4's linear regression
No fixed form — the model gets more complex as the data grows.
k-NN · trees in L10
Parametric: strong assumptions, needs less data. Non-parametric: flexible, needs more data and is slower. That's L6's bias–variance tradeoff.
Credit scoring, medical risk scores, churn and propensity models.
"Customers like you" recommendations, similarity search, filling gaps from similar rows.
Spam filters, sorting documents and support tickets, sentiment tagging.
In practice, the choice is often about constraints, not accuracy.
LR: which factors pushed the score.
k-NN: "these five past cases looked like you."
NB: the evidence from each feature.
NB: add to the counts.
k-NN: add the rows.
LR: refit the weights.
LR, NB: tiny and fast.
k-NN: the model is the data — memory, slow predictions, privacy.
In deployment, these properties often matter as much as accuracy.
04
Rows = truth · Columns = prediction
Sick, flagged sick — caught it.
Sick, cleared — usually the costliest error.
Healthy, flagged — a false alarm.
Healthy, cleared — correctly.
scikit-learn prints negatives first: [[TN, FP], [FN, TP]].
[[TN, FP], [FN, TP]]
AUC measures ranking; it does not choose your operating threshold.
05
Predict malignant vs benign · binary
Step 1 · Load & split
Positive class = the one we must catch. stratify=y keeps the balance in both splits.
stratify=y
Step 2 · Three pipelines
Step 3 · Cross-validate
Step 4 · Compare
Step 5 · The confusion matrix, for real
06
Start with one parameter
Heavy imbalance · alternative to ROC
Three or more classes · automatic
When the probability itself matters
0.5 is only the default