1. Home
  2. Explore
  3. Computer Science
  4. Machine Learning Theory

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Machine Learning Theory

Learning Theory Study Notes

Framing the Learning Problem

Core Assumptions

  • Data distribution: There exists a data generating distribution DDD from which (x,y)(x, y)(x,y) pairs are sampled. The training set and test-time examples are all drawn from the same distribution DDD. This is the foundational assumption for any learning theory.

  • Independent sampling: All samples are drawn independently from DDD. Together with the first assumption, this gives the i.i.d. (independent and identically distributed) setting.

The Learning Process

The learning process is modeled as:

  1. A training set S={(x1,y1),(x2,y2),…,(xm,ym)}S = \{(x_1, y_1), (x_2, y_2), \dots, (x_m, y_m)\}S={(x1​,y1​),(x2​,y2​),…,(xm​,ym​)} of mmm samples is drawn i.i.d. from DDD.

  2. This set is fed into a learning algorithm (a deterministic function).

  3. The output of the learning algorithm is a hypothesis hhh (or θ^\hat{\theta}θ^) — a function that maps new inputs xxx to predictions yyy.

Key insight: SSS is a random variable. Since the learning algorithm is deterministic, the output hypothesis hhh is also a random variable. The distribution of hhh is called the sampling distribution.

  • True parameter θ∗\theta^*θ∗ (or h∗h^*h∗) exists but is unknown. It is an unknown constant — not a random variable, but a fixed value that the learning algorithm aims to estimate.

  • The hypothesis is often parameterized (e.g., weights in logistic regression), but it can also be a non-parameterized function.

Bias-Variance Tradeoff

Data View vs. Parameter View

  • Data view: In regression, plots of xxx vs yyy show underfitting (high bias), overfitting (high variance), and "just right" fits.

  • Parameter view: More formal. Consider a two-dimensional parameter space (θ1,θ2)(\theta_1, \theta_2)(θ1​,θ2​). For a fixed sample size mmm, running the learning algorithm repeatedly (with different samples SSS) gives a set of θ^\hat{\theta}θ^ points — samples from the sampling distribution.

Definitions

  • Bias: Measures whether the sampling distribution is centered around the true parameter θ∗\theta^*θ∗. Formally, Bias(θ^)=E[θ^]−θ∗\text{Bias}(\hat{\theta}) = E[\hat{\theta}] - \theta^*Bias(θ^)=E[θ^]−θ∗.

  • Variance: Measures the dispersion of the sampling distribution. Formally, Var(θ^)=E[(θ^−E[θ^])2]\text{Var}(\hat{\theta}) = E[ (\hat{\theta} - E[\hat{\theta}])^2 ]Var(θ^)=E[(θ^−E[θ^])2].

High bias → the algorithm consistently stays away from θ∗\theta^*θ∗ regardless of data. High variance → the algorithm is easily swayed by noise in the data.

Properties

  • Bias and variance are independent — an algorithm can have any combination of high/low bias and high/low variance.

  • As sample size mmm increases, variance tends to zero. The rate at which variance decreases is called statistical efficiency.

  • Consistency: If θ^→θ∗\hat{\theta} \to \theta^*θ^→θ∗ as m→∞m \to \inftym→∞, the algorithm is consistent.

  • Unbiasedness: If E[θ^]=θ∗E[\hat{\theta}] = \theta^*E[θ^]=θ∗ for all mmm, the estimator is unbiased.

Fighting Variance

  • Get more data: Increasing mmm reduces variance naturally.

  • Regularization (L1, L2): Shrinks the hypothesis class, reducing the "wiggle room" for the estimator. This reduces variance but typically introduces a small amount of bias.

Fighting High Bias

  • Make the hypothesis class larger (e.g., use a more complex model). This reduces bias but usually increases variance.

  • Use a different algorithm.

The bias-variance tradeoff arises because steps that reduce bias (e.g., larger class) tend to increase variance, and steps that reduce variance (e.g., regularization, smaller class) tend to increase bias. The goal is to find the optimal balance that minimizes total generalization error.

Error Decomposition

Key Hypotheses

  • ggg: The best possible hypothesis (Bayes optimal) — minimizes the expected loss over DDD with infinite data.

  • h∗h_*h∗​: The best in-class hypothesis — the best hypothesis within a chosen hypothesis class H\mathcal{H}H (e.g., all logistic regression models).

  • h^\hat{h}h^: The hypothesis actually learned from finite data.

Types of Error

Define the risk (generalization error) of a hypothesis hhh as:

ϵ(h)=E(x,y)∼D[1{h(x)≠y}]\epsilon(h) = \mathbb{E}_{(x,y) \sim D} [\mathbf{1}\{h(x) \neq y\}]ϵ(h)=E(x,y)∼D​[1{h(x)=y}]

for classification (can be extended to regression). The empirical risk on a sample SSS is:

ϵ^S(h)=1m∑i=1m1{h(xi)≠yi}\hat{\epsilon}_S(h) = \frac{1}{m} \sum_{i=1}^m \mathbf{1}\{h(x_i) \neq y_i\}ϵ^S​(h)=m1​∑i=1m​1{h(xi​)=yi​}
  • Bayes error ϵ(g)\epsilon(g)ϵ(g): The irreducible error — even the best possible hypothesis may make mistakes (e.g., noisy labels).

  • Approximation error ϵ(h∗)−ϵ(g)\epsilon(h_*) - \epsilon(g)ϵ(h∗​)−ϵ(g): The cost of restricting ourselves to a specific hypothesis class H\mathcal{H}H. This is an attribute of the class.

  • Estimation error ϵ(h^)−ϵ(h∗)\epsilon(\hat{h}) - \epsilon(h_*)ϵ(h^)−ϵ(h∗​): The error due to having only a finite sample SSS.

Decomposition Identity

ϵ(h^)=ϵ(g)⏟Bayes+(ϵ(h∗)−ϵ(g))⏟approximation+(ϵ(h^)−ϵ(h∗))⏟estimation\epsilon(\hat{h}) = \underbrace{\epsilon(g)}_{\text{Bayes}} + \underbrace{(\epsilon(h_*) - \epsilon(g))}_{\text{approximation}} + \underbrace{(\epsilon(\hat{h}) - \epsilon(h_*))}_{\text{estimation}}ϵ(h^)=Bayesϵ(g)​​+approximation(ϵ(h∗​)−ϵ(g))​​+estimation(ϵ(h^)−ϵ(h∗​))​​
  • The estimation error can be further decomposed into estimation bias and estimation variance.

  • Sometimes the "bias-variance decomposition" groups approximation error into bias and estimation error into variance, but they are not exactly the same.

Takeaway: Generalization error = irreducible error + cost of class restriction (approximation) + cost of finite data (estimation). Approximation error is fixed for a given class; estimation error decreases as mmm increases.

Empirical Risk Minimization (ERM)

  • ERM is a specific learning algorithm: chooses the hypothesis that minimizes the empirical risk (training error) on the given sample:

    h^ERM=arg⁡min⁡h∈Hϵ^S(h)\hat{h}_{\text{ERM}} = \arg\min_{h \in \mathcal{H}} \hat{\epsilon}_S(h)h^ERM​=argminh∈H​ϵ^S​(h)
  • This is what many algorithms (e.g., logistic regression with cross-entropy loss) approximately do.

Two central questions about ERM:

  1. How does the empirical risk of a hypothesis relate to its generalization risk?

  2. How does the generalization error of the ERM hypothesis compare to the best possible generalization error in the class (h∗h_*h∗​)?

To answer these, we need tools from probability theory.

Uniform Convergence

Hoeffding's Inequality

For a Bernoulli distribution with parameter ϕ\phiϕ (bounded between 0 and 1), let Z1,…,ZmZ_1, \dots, Z_mZ1​,…,Zm​ be i.i.d. samples. Let ϕ^=1m∑Zi\hat{\phi} = \frac{1}{m} \sum Z_iϕ^​=m1​∑Zi​. Then for any margin γ>0\gamma > 0γ>0:

P(∣ϕ^−ϕ∣>γ)≤2exp⁡(−2γ2m)P(|\hat{\phi} - \phi| > \gamma) \leq 2 \exp(-2 \gamma^2 m)P(∣ϕ^​−ϕ∣>γ)≤2exp(−2γ2m)

Applied to a fixed hypothesis hhh: treat each sample's error indicator 1{h(xi)≠yi}\mathbf{1}\{h(x_i) \neq y_i\}1{h(xi​)=yi​} as a Bernoulli variable with true mean ϵ(h)\epsilon(h)ϵ(h). Then:

P(∣ϵ^S(h)−ϵ(h)∣>γ)≤2exp⁡(−2γ2m)P(|\hat{\epsilon}_S(h) - \epsilon(h)| > \gamma) \leq 2 \exp(-2 \gamma^2 m)P(∣ϵ^S​(h)−ϵ(h)∣>γ)≤2exp(−2γ2m)

From Fixed h to All h in a Finite Class

Assume the hypothesis class H\mathcal{H}H is finite with K=∣H∣K = |\mathcal{H}|K=∣H∣. Using the union bound over all hypotheses:

P(∃h∈H:∣ϵ^S(h)−ϵ(h)∣>γ)≤2Kexp⁡(−2γ2m)P\big( \exists h \in \mathcal{H} : |\hat{\epsilon}_S(h) - \epsilon(h)| > \gamma \big) \leq 2K \exp(-2 \gamma^2 m)P(∃h∈H:∣ϵ^S​(h)−ϵ(h)∣>γ)≤2Kexp(−2γ2m)

Taking the complement, with probability at least 1−δ1 - \delta1−δ (where δ=2Ke−2γ2m\delta = 2K e^{-2\gamma^2 m}δ=2Ke−2γ2m), for all h∈Hh \in \mathcal{H}h∈H:

∣ϵ^S(h)−ϵ(h)∣≤γ|\hat{\epsilon}_S(h) - \epsilon(h)| \leq \gamma∣ϵ^S​(h)−ϵ(h)∣≤γ

Sample Complexity

Fix γ\gammaγ and δ\deltaδ. Solving for mmm gives the sample complexity:

m≥12γ2log⁡2Kδm \geq \frac{1}{2\gamma^2} \log \frac{2K}{\delta}m≥2γ21​logδ2K​

With at least this many samples, the gap between empirical and generalization error is bounded by γ\gammaγ for all hypotheses, with high probability.

Relating ERM to Best in Class

Using the uniform convergence bound, we can bound the generalization error of the ERM hypothesis h^\hat{h}h^:

  1. ϵ(h^)≤ϵ^S(h^)+γ\epsilon(\hat{h}) \leq \hat{\epsilon}_S(\hat{h}) + \gammaϵ(h^)≤ϵ^S​(h^)+γ (by uniform convergence).

  2. ϵ^S(h^)≤ϵ^S(h∗)\hat{\epsilon}_S(\hat{h}) \leq \hat{\epsilon}_S(h_*)ϵ^S​(h^)≤ϵ^S​(h∗​) (since h^\hat{h}h^ minimizes empirical risk).

  3. ϵ^S(h∗)≤ϵ(h∗)+γ\hat{\epsilon}_S(h_*) \leq \epsilon(h_*) + \gammaϵ^S​(h∗​)≤ϵ(h∗​)+γ (again by uniform convergence).

Therefore:

ϵ(h^)≤ϵ(h∗)+2γ\epsilon(\hat{h}) \leq \epsilon(h_*) + 2\gammaϵ(h^)≤ϵ(h∗​)+2γ

Substituting γ=12mlog⁡2Kδ\gamma = \sqrt{ \frac{1}{2m} \log \frac{2K}{\delta} }γ=2m1​logδ2K​​, we get the bound:

ϵ(h^)≤ϵ(h∗)+212mlog⁡2Kδ\epsilon(\hat{h}) \leq \epsilon(h_*) + 2\sqrt{ \frac{1}{2m} \log \frac{2K}{\delta} }ϵ(h^)≤ϵ(h∗​)+22m1​logδ2K​​

This shows that with enough data, the ERM hypothesis performs almost as well as the best hypothesis in the class.

Infinite Hypothesis Classes and VC Dimension

For infinite hypothesis classes (e.g., neural networks, linear classifiers with real-valued parameters), we cannot use KKK directly. Instead, we use the Vapnik-Chervonenkis (VC) dimension, which measures the capacity or expressiveness of a hypothesis class.

  • VC dimension ddd is the size of the largest set of points that can be shattered (all possible labelings realized) by the class.

  • A similar uniform convergence bound exists, with sample complexity scaling as O(d)O(d)O(d):

    m≥O(dγ2log⁡1δ)m \geq O\left( \frac{d}{\gamma^2} \log \frac{1}{\delta} \right)m≥O(γ2d​logδ1​)

Key takeaway: The number of training examples needed to achieve good generalization is roughly proportional to the VC dimension of the hypothesis class. More complex models (higher VC dimension) require more data to avoid overfitting.


Summary of core theoretical results: Under i.i.d. assumptions, the generalization error of ERM is bounded by the best-in-class error plus a term that decreases as mmm increases — controlled by the size (KKK) or expressiveness (ddd) of the hypothesis class.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent