DS701 Session 11 — Tue Oct 13, 2026 (Monday schedule)
Describe what a \(k\)-nearest-neighbors classifier does at training time and at test time, and name the one hyperparameter that controls how complex the resulting model is. Is \(k\)-NN parametric or nonparametric, and why?
The lecture showed that in \(d\) dimensions the fraction of a unit ball’s volume lying in an outer shell of thickness \(\epsilon\) is \(f_d = 1-(1-\epsilon)^d\), and that the ratio of the minimum to the average pairwise distance among random points climbs toward 1 as \(d\) grows. Explain in your own words what these two facts do to the word “nearest” in \(k\)-nearest neighbors, and why that hurts the classifier.
State the “naive” assumption in Naive Bayes and say why it is called naive. Then connect it to the curse of dimensionality: a spam filter uses \(d = 1{,}000\) binary word features. Roughly how many probabilities per class must Naive Bayes estimate with the assumption versus without it, and why might Naive Bayes cope with those 1,000 features better than \(k\)-NN would?

walks like a duck, swims like a duck, quacks like a duck…


Iris, \(k = 2 \dots 19\), each point the mean of 50 random train/test splits.
Accuracy is not the whole story. Two-circles, 5-NN: 72% accuracy — but every Negative right and only half the Positives. Recall \(= TP/(TP+FN) = 50\%\); precision \(= TP/(TP+FP) = 100\%\). With 90/10 imbalance, “always predict the majority” scores 90% and is useless — read the confusion matrix, not the single number.



Fraction of a unit ball in its outer \(\epsilon\)-shell: \(f_d = 1-(1-\epsilon)^d \to 1\).

1,000 uniform points: min pairwise distance / average pairwise distance \(\to 1\).
Both say: in high \(d\) every candidate neighbour sits at about the same distance. The \(k\) “nearest” are a random handful; classifying from them is like classifying from points at the average distance. What helps: a different dissimilarity (cosine did a little better), or reduce the dimension — feature selection, PCA/SVD (lectures 12–13). Today’s activity measures all of this.
\[ P(C_i \mid \mathbf{x}) = \frac{P(\mathbf{x} \mid C_i)\,P(C_i)}{P(\mathbf{x})} \qquad\Longrightarrow\qquad \hat{C} = \arg\max_{C_i} \; P(\mathbf{x} \mid C_i)\,P(C_i) \]
\[ P(x_1,\dots,x_d \mid C_i) \;=\; \prod_{j=1}^{d} P(x_j \mid C_i) \]

Goal: on your section’s slice of a real diagnostic dataset, sweep \(k\) under two metrics and choose it by cross-validation, then pit \(k\)-NN against Gaussian Naive Bayes and a decision tree — accuracy, confusion matrix, precision, recall — and hand-compute Naive Bayes on a toy table. Then measure the curse: nearest/farthest distance ratios and shell volumes as \(d\) grows, watch \(k\)-NN collapse as noise dimensions are added, and rescue it — and find out whether Naive Bayes suffers the same way.
numpy, pandas, matplotlib, scipy, scikit-learn.The activity notebook goes live on the day of the lecture. Colab is optional — you can also open it on GitHub and run it locally.
Full lecture notes: \(k\)-Nearest Neighbors, Curse of Dimensionality, and Naive Bayes