Introduction

web.stanford.edu/class/stats202

Sergio Bacallado, Jonathan Taylor

Autumn 2022

Prediction challenges

The MNIST dataset is a library of handwritten digits

MNIST dataset

The Netflix prize

Netflix popularized prediction challenges by organizing an open, blind contest to improve its recommendation system.

The prize was $1 million.

(Cue Dr. Evil jokes if anyone knows Austin Powers movies…)

Unsupervised learning

In unsupervised learning we start with a data matrix:

Unsupervised learning setup

Goals of unsupervised learning

In unsupervised learning we start with a data matrix:

Our goal is to:

  1. Find meaningful relationships between the variables or units: Correlation analysis.

  2. Find interpretable low-dimensional representations of the data which make it easy to visualize the variables and units. PCA, ICA, isomap, locally linear embeddings, etc.

  3. Find meaningful groupings of the data. Clustering.

Unsupervised learning is sometimes referred to in Statistics as exploratory data analysis.

Striking example

Supervised learning

Setup

In supervised learning, there are input variables, and output variables:

Typical regression problem

Classification problems

In supervised learning, there are input variables, and output variables:

Typical classification problem

Goals of supervised learning

In supervised learning, there are input variables, and output variables:

\[Y = f(X) + \underbrace{ \varepsilon}_{\text{Random error}}\]

Regression model

\[Y = f(X) + \varepsilon\]

Task Example
Prediction
  • Useful when the input variable is readily available, but the output variable is not.
  • Predict stock prices next month using data from last year.
Inference
  • A model for \(f\) can help us understand the structure of the data: which variables influence the output, and which don’t?
  • What is the relationship between each variable and the output, e.g. linear, non-linear?
  • What is the influence of genetic variations on the incidence of heart disease?

Parametric and nonparametric methods

There are (broadly) two kinds of supervised learning method:

\[f(X) = X_1\beta_1+\dots +X_p\beta_p\]

with parameters \(\beta_1,\dots,\beta_p\). Using the training data, we try to fit the parameters.

Parametric vs. nonparametric prediction

Parametric Non-parametric
Fig 2.4 Fig 2.5
  1. Parametric methods have a limit of fit quality. Non-parametric methods can keep improving as we add more data to fit.

  2. Parametric methods are often simpler to interpret.

Prediction error

\[MSE(\hat f) = E(y_0 - \hat f(x_0))^2.\]

\[MSE_\text{training}(\hat f) = \frac{1}{n}\sum_{i=1}^n (y_i-\hat f(x_i))^2.\]

\[ \hat{f} = \text{argmin}_{f \in {\cal M}} MSE_{\text{training}}(f) \]

Key quantities

Term Quantity
Training data \((x_1,y_1),(x_2,y_2)\dots (x_n,y_n)\)
Predicted function \(\hat f\), a function of (i.e. learned on) training data
Future data \((x_0,y_0)\) having some distribution (usually related to distribution of training data)
Prediction error (MSE) \(MSE(\hat f) = E(y_0 - \hat f(x_0))^2.\)

Test vs. training error

  1. The main challenge of statistical learning is that a low training MSE does not imply a low MSE.

  2. If we have test data \(\{(x'_i,y'_i);i=1,\dots,m\}\) which were not used to fit the model, a better measure of quality for \(\hat f\) is the test MSE:

\[MSE_\text{test}(\hat f) = \frac{1}{m}\sum_{i=1}^m (y'_i-\hat f(x'_i))^2.\]

Prediction error vs. flexibility

The circles are simulated data from the black curve \(f\) by adding Gaussian noise. In this artificial example, we know what \(f\) is.

Three estimates \(\hat f\) are shown: Linear regression, Splines (very smooth), Splines (quite rough).

Red line: Test MSE, Gray line: Training MSE.

Prediction error vs. flexibility

The function \(f\) is now almost linear.

Prediction error vs. flexibility

When the noise \(\varepsilon\) has small variance relative to \(f\), the third method does well.

Bias variance decomposition

\[MSE(\hat{f}, x_0) = E( y_0 - \hat f(x_0))^2 = \text{Var}(\hat f(x_0)) + [\text{Bias}(\hat f(x_0))]^2 + \text{Var}(\varepsilon_0)\]

Term Quantity
Variance
  • \(\text{Var}(\hat f(x_0))\)
  • The variance of the estimate of \(Y\): \(E[\hat f(x_0) - E(\hat f(x_0))]^2\)
Bias (squared)
  • \([\text{Bias}(\hat f(x_0))]^2\)
  • This measures how much the estimate of \(\hat f\) at \(x_0\) changes when we sample and average over new training data.
Irreducible error
  • \(\text{Var}(\varepsilon_0)\)
  • This is how much of the response is not predictable by any method.

Simulation example

Sample #1 Sample #2 Sample #3 Sample #4
All fits Bias

Implications of bias variance decomposition

\[MSE(\hat{f}, x_0) = E(y_0 - \hat f(x_0))^2 = \text{Var}(\hat f(x_0)) + [\text{Bias}(\hat f(x_0))]^2 + \text{Var}(\varepsilon).\]

  1. The MSE is always positive.

  2. Each element on the right hand side is always positive.

  3. Therefore, typically when we decrease the bias beyond some point, we increase the variance, and vice-versa.

More flexibility \(\iff\) Higher variance \(\iff\) Lower bias.

Classification problems

\[\cancel{Y=f(X)+\epsilon}\]

\[ \begin{aligned} P(X,Y): & \text{ joint distribution of }(X,Y),\\ P(Y\mid X): &\text{ conditional distribution of }Y\text{ given }X,\\ \hat y_i: &\text{ prediction for }x_i. \end{aligned} \]

Loss function for classification

\[E(\mathbf{1}(y_0 \neq \hat y_0) )\]

\[\frac{1}{n}\sum_{i=1}^n\mathbf{1}(y_i \neq \hat y_i)\]

Bayes classifier

Bayes decision boundary

\[\hat y_i = \text{argmax}_j \;\; P(Y=j \mid X= x_i)\]