
Lecture 12: Non-parametric Models
Intro to Machine Learning

Recall

linear models: learn \(\theta, \theta_0\)

polynomial features: learn \(\theta\) on \(\phi(x)\)

neural networks: learn \(W^1,\dots,W^L\)

CNNs: learn filter weights

transformers: learn \(W_q, W_k, W_v, \dots\)

fitted Q-learning: learn \(\theta\) in \(\mathrm{Q}_\theta(s,a)\)
every time: the map from input to output has a fixed functional form, and we learn a fixed number of parameters, regardless of the number of data points.
Today: non-parametric models
non-parametric: no form fixed in advance; the data shapes the model.
all models have parameters, but not all are parametric,
just as all systems have mechanisms, but not all are mechanical
Why still care, in the days of deep learning?
- readable: a prediction traces back to a few examples or questions
- strong baselines: quick to try, and the first sanity check
- flexible: complexity can grow with data
- complementary: alongside deep learning, not competing with it
Outline
- \(k\)-nearest neighbors
- \(k\)-means clustering
- Tree-based methods
- \(k\)-nearest neighbors
- \(k\)-means clustering
- Tree-based methods
Retrieval-Augmented Generation (RAG)
RAG

agentic RAG: retrieval becomes a tool

[image credit: Pinecone]
Predict by copying the nearest neighbors

training data. each point has features \((x_1,x_2)\) and a label, its color. there is no training step: we just keep the points.

\(k=1\). a new point arrives. measure its distance to every stored point, and copy the nearest one’s label: orange.

\(k=5\). keep the five nearest and let them vote: 3 navy, 2 orange. the most votes win: navy. the prediction changed.




training data
\(k=3\)
\(k=5\)
\(k=10\)
\(x_1\)
\(x_2\)
\(x_1\)
\(x_2\)
\(x_1\)
\(x_2\)
\(x_1\)
\(x_2\)
The hyperparameter \(k\)
more neighbors voting gives a smoother boundary.
we pick \(k\) by validation. the distance metric is a hyperparameter too.
we sweep over the feature space and color each point by its \(k\)-NN prediction.
\(k\)-NN for regression

one prediction, \(k=3\). find the three nearest points along \(x\) and average their \(y\) values.

\(k=1\). sweep \(x_{\text{new}}\) across the axis: the prediction copies the nearest point, a staircase through every point.

\(k=5\). averaging five neighbors gives a smoother curve.
Non-parametric: complexity grows with the data
for the same hyperparameter \(k=3\)

\(k\)-NN as an image classifier


a deep net learns a latent representation of each photo.
the classification is done by \(k\)-NN in that space.
interpretability: four randomly sampled misclassified photos. under each query is its true label; the prediction is the neighbors’ vote.
\(k\)-NN lets us examine the source of an error (the benchmark dataset label seems to be the culprit here).
Geirhos, Jaini, Stone, et al. Towards flexible perception with visual memory. Google DeepMind, 2024.
- store: every training context, with the word that came next.
- look up: the \(k\) stored contexts nearest to the new one; their next words vote.
- blend: mix that vote with the language model’s own prediction.

Khandelwal, Levy, Jurafsky, et al. Generalization through Memorization: Nearest Neighbor Language Models. ICLR 2020.
\(k\)NN-LM: language models that look up
Be cautious when…
- \(n\) or \(d\) is large: each prediction scans all \(n\) points; in high dimensions, all points are far apart.
- features sit on different scales: the largest one dominates the distance, so we rescale first.

raw units: \(x_1\) spans 100, \(x_2\) only 10, so the nearest five sit in a thin band. vote: 4 orange, 1 navy.

\(x_1\) rescaled to match \(x_2\): both count. vote: 5 navy.
Outline
- \(k\)-nearest neighbors
- \(k\)-means clustering
- Tree-based methods
No labeled categories, we can still group by similarities.

Comprehensive Integration of Single-Cell Data

cells group into types, some new
each cell: a vector of gene activity

Novel subgroups of adult-onset diabetes and their association with outcomes: a data-driven cluster analysis of six variables

adult diabetes splits into five subgroups
the usual diagnosis called almost all “type 2”

Hunting for open clusters in Gaia DR2: 582 new open clusters in the Galactic disc

582 new star clusters (black), known ones (red)
grouped by position and motion
Food-truck placement

- \(x_1\): longitude, \(x_2\): latitude
- \(n\) people, person \(i\) at location \(x^{(i)}\)
- \(k\) food trucks (say \(k=5\))
- truck \(j\) at location \(\mu^{(j)}\)
- person \(i\) walks to truck \(y^{(i)}\)

the goal: group the people, one truck per group.
From one person’s loss to the \(k\)-means objective

Person \(i\)'s loss:
\(\sum_{j=1}^{k} \mathbf{1}\{y^{(i)} = j\}\, \big\|x^{(i)} - \mu^{(j)}\big\|^2\)
\(\big\|x^{(i)} - \mu^{(j)}\big\|^2\): distance between person \(i\) and truck \(j\), squared.
\(\mathbf{1}\{y^{(i)} = j\}\): only the truck person \(i\) actually walks to counts.
Everyone’s loss, the \(k\)-means objective:
\(\sum_{i=1}^{n}\sum_{j=1}^{k} \mathbf{1}\{\textcolor{#638d69}{y^{(i)}} = j\}\, \big\|x^{(i)} - \textcolor{#638d69}{\mu^{(j)}}\big\|^2\)
what we learn: memberships \(y^{(i)}\) and centroids \(\mu^{(j)}\).
K-MEANS\((k, \tau, \left\{x^{(i)}\right\}_{i=1}^n)\)
1 \(\mu, y=\) random initialization
2 for \(t=1\) to \(\tau\)
4 for \(i=1\) to \(n\)
\(5 \quad \quad\quad\quad \quad y^{(i)}=\arg \min _j\left\|x^{(i)}-\mu^{(j)}\right\|^2\)
6 for \(j=1\) to \(k\)
\(7 \quad \quad\quad\quad \quad \mu^{(j)}=\frac{1}{N_j} \sum_{i=1}^n \mathbf{1}\left(y^{(i)}=\mathfrak{j}\right) x^{(i)}\)
8 if \(y==y_{\text {old }}\)
9\(\quad \quad \quad\quad \quad\)break
10 return \(\mu, y\)

3 \(y_{\text {old }} = y\)
initialization
subroutine A
subroutine B
\(k\)-means, one round

Initialization
random trucks, random colors (line 1)

Subroutine A, assignment
each student gets assigned to the nearest truck (line 5)

Subroutine B, centroid update
each truck moves to the mean of its students (line 7)
neither subroutine can raise the objective. once the assignments stop changing, we have converged.
\(k\)-means is sensitive to initialization and to \(k\)
same data, three different initializations:



same data, two different choices of \(k\):


(\(k\)-means works well for well-separated circular clusters of the same size)








\(k\)-means in current systems

Clio Anthropic, 2024
a million chats to analyze, a privacy and scale issue.
\(k\)-means on their embeddings finds the topics.
findings: coding dominates, use differs by language (e.g., Japanese conversations discuss elder care at higher rates)
see also: Faiss (Meta, 2024) on how \(k\)-means helps \(k\)-NN scale · OpenAI’s embeddings guide on \(k\)-means with embeddings
Outline
- \(k\)-nearest neighbors
- \(k\)-means clustering
- Tree-based methods
A learned if-then list

it was learned from data, and it predicts re-arrest about as accurately as a proprietary black box that uses 130+ factors.

Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead
Each internal node carries a split dimension and split value (\(x_j \geq s\)).
Each leaf corresponds to an axis-aligned region; the tree predicts the leaf's value there.
A tree splits the input space into regions


- Choose \(k=2\)
- \(\operatorname{BuildTree}(\{1,2,3\};2)\)
- \(|I| = |\{1,2,3\}| = 3\), more than a leaf can hold (\(k=2\)), so line 1 is true.
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
set of indices
max leaf size, a hyperparameter: a region with at most \(k\) points is not split further; it becomes a leaf.
1. if \(|I| > k\)

\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
- For this fixed \((j, s)\)
- \(I_{j, s}^{+} = \{2,3\}\) (line 3)
- \(I_{j, s}^{-} = \{1\}\) (line 4)
- \(\hat{y}_{j, s}^{+} = \frac{5+3}{2} = 4\) (line 5)
- \(\hat{y}_{j, s}^{-} = 0\) (line 6)
- \(E_{j, s} = 1^2 + 1^2 = 2\) (line 7)
- another \((j, s)\) leads to the same quantities, lines 3 to 7

\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
Line 2: only finitely many \((j, s)\) matter, those that split between data points.
Line 8: picks the best of them (random tie-breaking).

\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
Line 12, recurse
\(x_1 \geq 1.7\)
1.7
Suppose line 8 picks \((j^*,s^*) = (1, 1.7)\).

\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
\(x_1 \geq 1.7\)
0
the left call, \(\operatorname{BuildTree}(\{1\}; 2)\), starts again at line 1.
\(|I| = 1\) is not more than \(k=2\), so line 1 is false: a leaf, \(\hat{y} = 0\).

\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) average \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) average \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s}=\sum_{i \in I_{j, s}^{+}}\left(y^{(i)}-\hat{y}_{j, s}^{+}\right)^2+\sum_{i \in I_{j, s}^{-}}\left(y^{(i)}-\hat{y}_{j, s}^{-}\right)^2\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
10. Set \(\hat{y}=\) average \(_{i \in I} y^{(i)}\)
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
\(x_1 \geq 1.7\)
0
4
the right call, \(\operatorname{BuildTree}(\{2,3\}; 2)\), also starts at line 1.
\(|I| = 2\) is not more than \(k=2\): a leaf, \(\hat{y} = \frac{5+3}{2} = 4\).
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) majority \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) majority \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) majority \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s} = \frac{\left|I_{j, s}^{-}\right|}{|I|} \cdot H\left(I_{j, s}^{-}\right)+\frac{\left|I_{j, s}^{+}\right|}{|I|} \cdot H\left(I_{j, s}^{+}\right)\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)
weighted average entropy (WAE)
as performance metric
majority vote
as regional prediction
For classification
entropy \(H:=-\sum_{\text {class }_c} \hat{P}_c (\log _2 \hat{P}_c)\)
(= 1)
for example: \(c\) iterates over 3 classes

\(\hat{P}_c:\)
\(H= -[\frac{4}{6} \log _2\left(\frac{4}{6}\right)+\frac{1}{6} \log _2\left(\frac{1}{6}\right)+\frac{1}{6} \log _2\left(\frac{1}{6}\right)]\)
(about 1.252)

\(\hat{P}_c:\)
\(H= -[\frac{3}{6} \log _2\left(\frac{3}{6}\right)+\frac{3}{6} \log _2\left(\frac{3}{6}\right)+ 0]\)

\(\hat{P}_c:\)
\(H= -[\frac{6}{6} \log _2\left(\frac{6}{6}\right)+ 0+ 0]\)
(= 0)
empirical probability
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) majority \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) majority \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) majority \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s} = \frac{\left|I_{j, s}^{-}\right|}{|I|} \cdot H\left(I_{j, s}^{-}\right)+\frac{\left|I_{j, s}^{+}\right|}{|I|} \cdot H\left(I_{j, s}^{+}\right)\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)

\(E_{j, s} = \textcolor{#b14152}{\frac{4}{6} \cdot H\left(I_{j, s}^{-}\right)}+\textcolor{#4d619d}{\frac{2}{6} \cdot H\left(I_{j, s}^{+}\right)}\)
the weights are the share of points on each side.
\(\textcolor{#b14152}{H\left(I_{j, s}^{-}\right) = -[\frac{3}{4} \log _2\left(\frac{3}{4}\right)+\frac{1}{4} \log _2\left(\frac{1}{4}\right)+0] \approx 0.811}\)
\(\textcolor{#4d619d}{H\left(I_{j, s}^{+}\right) = -[\frac{1}{2} \log _2\left(\frac{1}{2}\right)+0+\frac{1}{2} \log _2\left(\frac{1}{2}\right)] = 1}\)
\(E_{j, s} \approx \textcolor{#b14152}{\frac{4}{6} \cdot 0.811}+\textcolor{#4d619d}{\frac{2}{6} \cdot 1} \approx 0.874\)
choose \(k=2\)
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) majority \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) majority \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) majority \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s} = \frac{\left|I_{j, s}^{-}\right|}{|I|} \cdot H\left(I_{j, s}^{-}\right)+\frac{\left|I_{j, s}^{+}\right|}{|I|} \cdot H\left(I_{j, s}^{+}\right)\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)

\(E_{j, s} = \textcolor{#b14152}{\frac{5}{6} \cdot H\left(I_{j, s}^{-}\right)}+\textcolor{#4d619d}{\frac{1}{6} \cdot H\left(I_{j, s}^{+}\right)}\)
\(\textcolor{#b14152}{H\left(I_{j, s}^{-}\right) = -[\frac{4}{5} \log _2\left(\frac{4}{5}\right)+\frac{1}{5} \log _2\left(\frac{1}{5}\right)+0] \approx 0.722}\)
\(\textcolor{#4d619d}{H\left(I_{j, s}^{+}\right) = -[1 \log _2\left(1\right)+0+0] = 0}\)
\(E_{j, s} \approx \textcolor{#b14152}{\frac{5}{6} \cdot 0.722}+\textcolor{#4d619d}{\frac{1}{6} \cdot 0} \approx 0.602\)
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) majority \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) majority \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) majority \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s} = \frac{\left|I_{j, s}^{-}\right|}{|I|} \cdot H\left(I_{j, s}^{-}\right)+\frac{\left|I_{j, s}^{+}\right|}{|I|} \cdot H\left(I_{j, s}^{+}\right)\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)

this split \(E_{j, s}\approx\) 0.602
this split \(E_{j, s}\approx\) 0.874
line 8, set the better \((j, s)\)
\(\operatorname{BuildTree}(I, k, \mathcal{D})\)
10. Set \(\hat{y}=\) majority \(_{i \in I} y^{(i)}\)
1. if \(|I| > k\)
2. for each split dim \(j\) and split value \(s\)
3. Set \(I_{j, s}^{+}=\left\{i \in I \mid x_j^{(i)} \geq s\right\}\)
4. Set \(I_{j, s}^{-}=\left\{i \in I \mid x_j^{(i)}<s\right\}\)
5. Set \(\hat{y}_{j, s}^{+}=\) majority \(_{i \in I_{j, s}^{+}} y^{(i)}\)
6. Set \(\hat{y}_{j, s}^{-}=\) majority \(_{i \in I_{j, s}^{-}} y^{(i)}\)
7. Set \(E_{j, s} = \frac{\left|I_{j, s}^{-}\right|}{|I|} \cdot H\left(I_{j, s}^{-}\right)+\frac{\left|I_{j, s}^{+}\right|}{|I|} \cdot H\left(I_{j, s}^{+}\right)\)
8. Set \(\left(j^*, s^*\right)=\arg \min _{j, s} E_{j, s}\)
9. else
11. return \(\operatorname{Leaf}\)(leave_value=\(\hat{y})\)
12. return \(\operatorname{Node}\left(j^*, s^*, \operatorname{BuildTree}\left(I_{j^*, s^*}^{-}, k\right), \operatorname{BuildTree}\left(I_{j^*, s^*}^{+}, k\right)\right)\)

line 12, recurse on each side
\(x_1 \geq s^*\)
BuildTree(5 points)
BuildTree(1 point)
right call: one point, so line 1 is false and it returns a leaf. left call: starts again at line 1, exactly as in regression.
With \(k=2\): the full tree, then pruning

\(x_1 \geq s^*\)
■
\(x_2 \geq s_2\)
●
\(x_1 \geq s_3\)
★
★
the four stars are more than \(k=2\), so line 1 forces one more split (dashed). every candidate ties at entropy 0; this is one possible outcome.
both of its leaves predict ★, so that split changes nothing: we prune it.
in general, pruning removes splits that help too little: slightly less training fit, a simpler tree.
★
\(s^*\)
\(s_3\)
\(s_2\)
Bagging =
Bootstrap aggregating
Training data \(\mathcal{D}_n\)
\(\left(x^{(1)}, y^{(1)}\right)\)
\(\left(x^{(2)}, y^{(2)}\right)\)
\(\left(x^{(3)}, y^{(3)}\right)\)
\(\left(x^{(4)}, y^{(4)}\right)\)
\(\tilde{\mathcal{D}}_n^{(1)}\)
\(\tilde{x}^{(1)}, \tilde{y}^{(1)}\)
\(\tilde{x}^{(2)}, \tilde{y}^{(2)}\)
\(\tilde{x}^{(4)}, \tilde{y}^{(4)}\)
\(\tilde{x}^{(3)}, \tilde{y}^{(3)}\)
\(\tilde{\mathcal{D}}_n^{(2)}\)
\(\tilde{x}^{(1)}, \tilde{y}^{(1)}\)
\(\tilde{x}^{(2)}, \tilde{y}^{(2)}\)
\(\tilde{x}^{(4)}, \tilde{y}^{(4)}\)
\(\tilde{x}^{(3)}, \tilde{y}^{(3)}\)
\(\left(x^{(2)}, y^{(2)}\right)\)
\(\tilde{\mathcal{D}}_n^{(B)}\)
\(\tilde{x}^{(4)}, \tilde{y}^{(4)}\)
\(\tilde{x}^{(3)}, \tilde{y}^{(3)}\)
\(\tilde{x}^{(1)}, \tilde{y}^{(1)}\)
\(\hat{h}^{(B)}\)
\(\hat{h}^{(1)}\)
\(\hat{h}^{(2)}\)
for regression, average; for classification, vote
\(\hat{h}_{\text {bag }}(x)\)
More broadly: ensembles



train several models, then aggregate their predictions: an ensemble. bagging is one kind.
the models can even come from different model classes:
on tabular benchmarks, an ensemble across model classes (the dashed line) sits above every single class.
Erickson et al. TabArena. NeurIPS 2025.
Trees on tabular data: 2022 and today
why: a tree asks about one column at a time and can jump at any threshold. tables reward that: jumpy targets, columns with their own meaning, and some columns worth ignoring.

34 medium-sized datasets (2022): tree ensembles finish on top in both panels
- by 2025: tuned neural nets have caught up, and ensembles across model classes lead.
- TabPFN (transformers lecture): the test row attends to every training row, a soft \(k\)-NN.
Grinsztajn et al., NeurIPS 2022. Erickson et al. TabArena. NeurIPS 2025. Hollmann et al. TabPFN. Nature 2025.
Summary
Non-parametric models: no functional form chosen in advance; the model can grow with the data.
\(k\)-nearest neighbors: predict from the \(k\) nearest stored points. \(k\) and the distance are hyperparameters.
\(k\)-means: alternate assignment and centroid update to lower one objective. the result depends on initialization and \(k\).
Decision trees: split to make regions pure, by squared error or entropy. a prediction is a short chain of questions.
Bagging: train trees on resampled data and aggregate them. more broadly, an ensemble aggregates several models, even across model classes.
In practice they combine with deep models: embeddings from a network, a lookup or a tree on top.
6.390 IntroML (Fall26) - Lecture 12 Non-parametric Models
By Shen Shen
6.390 IntroML (Fall26) - Lecture 12 Non-parametric Models
6.390 Intro to Machine Learning, Fall 2026. Lecture 12: Non-parametric Models
- 32