02 statLearning

📚 02_statLearning.pptx

Brief overview

This document introduces the foundational concepts of statistical learning, focusing on predicting a response variable from predictor variables. It explores different model types, accuracy assessment, and the critical bias-variance trade-off, providing essential tools for understanding and building predictive models.

Key points

  • Introduction to statistical learning and its core purpose in predicting responses.
  • Comparison of parametric and nonparametric models and the curse of dimensionality.
  • Assessing model accuracy using test data and the bias-variance trade-off.
  • Classification problems, conditional class probabilities, and performance evaluation.
  • Introduction to the Bayes classifier and support-vector machines.

1. Introduction to statistical learning

1.1 What is statistical learning?

Statistical learning aims to predict a response variable (YY) using one or more predictor variables (XX). For example, we might predict product sales based on advertising spend on TV, radio, and newspapers.

This relationship can be expressed as Y=f(X)+ϵY = f(X) + \epsilon. Here, f(X)f(X) represents the systematic relationship between XX and YY.

The term ϵ\epsilon accounts for random errors and unpredictable variations.

This scatter plot illustrates a linear regression model, showing observed data points, the regression line, and the concept of random error.

The figure above shows how observed sales data points relate to an advertising spend. The red line represents a fitted regression model, indicating the general trend.

The vertical distance from each data point to the line represents the error, ϵ\epsilon.

1.2 The regression function f(X)f(X)

The core goal in statistical learning is to estimate the regression function, f(X)=E(Y∣X=x)f(X) = E(Y | X = x). This function represents the expected value of the response variable YY given specific values of the predictor variables XX.

Estimating f(X)f(X) helps us achieve two main objectives:

  • Prediction: To forecast the response variable (YY) for new observations of predictor variables (XX).
  • Inference: To understand which predictor variables are important for explaining YY and how they affect it. For instance, in predicting income, variables like seniority and education might be significant, while marital status might not be.

A 3D scatter plot showing the relationship between years of education, seniority, and income.

This 3D scatter plot visualizes how income relates to both years of education and seniority. It helps understand which factors have a stronger influence on income levels.

1.3 Estimating f(X)f(X)

Estimating f(X)f(X) involves finding a function f^(X)\hat{f}(X) that closely approximates the true regression function. The accuracy of this estimate is often measured by the mean-squared prediction error, E[(Y−f^(X))2]E[(Y - \hat{f}(X))^2].

This error can be decomposed into two parts:

  • Reducible Error: This is the error resulting from the difference between the true function f(X)f(X) and our estimate f^(X)\hat{f}(X), i.e., (f(X)−f^(X))2(f(X) - \hat{f}(X))^2. This error can be reduced by improving our estimation method.
  • Irreducible Error: This is the error represented by the variance of the random term ϵ\epsilon, denoted as Var(ϵ)\text{Var}(\epsilon). This error is inherent in the data and cannot be reduced by any model.

E[(Y−f^(X))2∣X=x]=(f(x)−f^(x))2+Var(ϵ)E[(Y - \hat{f}(X))^2 | X=x] = (f(x) - \hat{f}(x))^2 + \text{Var}(\epsilon)

A scatter plot shows the relationship between x and y variables, with a regression line and a vertical line at x=4.

This plot illustrates estimating f(x)f(x) at a specific value, x=4x=4. The regression line shows the expected YY value for X=4X=4.

The scatter of points around this line represents the irreducible error.

A scatter plot shows the relationship between two variables, with a fitted curve and a vertical line highlighting a specific point.

Here, a fitted curve represents the estimated regression function f^(x)\hat{f}(x). The vertical line at x=4x=4 shows a specific point of interest for prediction or analysis.

1.3.1 Parametric vs. Nonparametric approaches

There are two main approaches to estimating f(X)f(X):

ApproachDescription
ParametricAssumes a specific functional form for f(X)f(X) (e.g., linear) and then estimates its parameters using data.
NonparametricDoes not assume a specific functional form for f(X)f(X), allowing the model to adapt flexibly to the data.

📝 Example: A parametric approach might assume sales are linearly related to TV ad spend: Sales = β0+β1×TV\beta_0 + \beta_1 \times \text{TV}. A nonparametric approach would try to fit a curve without pre-defining its shape.

Both parametric and nonparametric methods can lead to "overfitting," where the model learns the training data too well, including its noise, and performs poorly on new data.

🔑 Important: The goal is to find an estimate f^(x)\hat{f}(x) that minimizes prediction error, balancing the reduction of reducible error without increasing irreducible error.

1.4 Challenges in estimation

Directly calculating E(Y∣X=x)E(Y | X = x) is often impossible because we rarely have exact data points for a specific X=xX=x. Instead, we estimate f(x)f(x) by averaging YY values in a neighborhood around xx.

This is represented as f^(x)=Ave(Y∣X∈N(x))\hat{f}(x) = \text{Ave}(Y | X \in N(x)), where N(x)N(x) denotes a neighborhood around xx.

🔑 Important: Statistical learning provides methods to approximate f(X)f(X) by considering data points close to the target value X=xX=x.

2. Model types and the curse of dimensionality

2.1 The curse of dimensionality

The curse of dimensionality describes a problem where model performance degrades as the number of predictors increases. This is particularly problematic for methods like nearest neighbor averaging.

In low dimensions, neighbors are typically close. However, in high dimensions, "neighbors" tend to be much farther away.

To achieve reliable estimates, nearest neighbor methods need to average a significant fraction of the data. As dimensions increase, the volume of space grows.

This means a fixed percentage of data points will occupy a larger and larger volume. Consequently, these points are no longer truly "local."

The volume of a hypercube grows exponentially with its dimension.

2.2 Parametric vs. nonparametric models

Model types can be broadly categorized into parametric and nonparametric approaches. Each has distinct assumptions and implications for fitting data.

2.2.1 Parametric models

Parametric models assume a specific functional form for the relationship between predictors and the outcome. This form is defined by a fixed set of parameters.

The model's goal is to estimate these parameters from the training data.

A common example is the linear model: fL(X)=β0+β1X1+β2X2+⋯+βpXpf_L(X) = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots + \beta_p X_p This model is specified by p+1p+1 parameters: {β0,β1,…,βp}\{\beta_0, \beta_1, \dots, \beta_p\}. While often not perfectly correct, linear models can serve as useful and interpretable approximations.

Parametric models simplify reality by assuming a known structure.

2.2.2 Nonparametric models

Nonparametric models do not assume a predefined functional form. Instead, they aim to fit the data as closely as possible without imposing too much structure.

They can adapt to a wider variety of underlying data shapes.

These models have the potential for greater accuracy by capturing complex relationships. However, they are also more prone to overfitting.

Nonparametric models are flexible but require more data to generalize well.

2.2.3 Comparing model types

Model TypeAssumptionsFlexibilityInterpretabilityOverfitting RiskData Needs
ParametricSpecific functional form (e.g., linear)LowHighLowerModerate
NonparametricNo specific functional form assumedHighLowerHigherHigh

The choice between parametric and nonparametric models often involves a trade-off. Parametric models offer clarity but may oversimplify.

Nonparametric models can capture intricate patterns but demand more data and are harder to explain.

This chart displays three different models fitted to a set of data points, illustrating the concepts of underfitting, overfitting, and optimal fitting.

The figure above illustrates this. A simple linear model (parametric) might underfit.

A highly complex polynomial model (parametric) might overfit. An optimal model balances fitting the trend without capturing noise.

This chart compares polynomial regression with nonparametric regression using KNN.

This comparison shows how a polynomial regression (parametric) creates a smooth curve. A K-Nearest Neighbors (KNN) regression (nonparametric) creates a step-like fit, adapting more locally to the data.

Both aim to model the underlying trend.

🔑 Important: Parametric models are easier to interpret, while nonparametric models can capture more complex patterns but risk overfitting.

🔑 Important: The curse of dimensionality affects nonparametric methods more severely as they require dense data to find truly local neighbors.

3. Model accuracy and the bias-variance trade-off

3.1 Assessing model accuracy

  • Goal: Evaluate how well a model performs on new, unseen data.
  • Training Error: Calculated on the data used to train the model. This can be misleading as it may favor models that overfit.
  • Test Error: Calculated on a separate dataset not used during training. This provides a more unbiased estimate of performance.

Key takeaway: Always assess models using test data for an accurate performance measure.

3.2 Overfitting and underfitting

  • Overfitting: A model fits the training data too closely, including noise. This leads to poor performance on new data.
  • Underfitting: A model is too simple to capture the underlying patterns in the data. This also results in poor performance.
  • Good Fit: A model that balances complexity to capture patterns without overfitting.

3.3 The bias-variance trade-off

This trade-off describes the relationship between a model's flexibility, its bias, and its variance.

  • Bias: The error introduced by approximating a real-world problem, which may be complex, by a simpler model. High bias means the model makes strong assumptions and may underfit.
  • Variance: The amount by which the estimate of the true value of a parameter will vary if repeated calculations are performed on different datasets. High variance means the model is sensitive to training data fluctuations and may overfit.
  • Irreducible Error: The inherent noise in the data that cannot be reduced by any model.

The formula for the expected test error is: E[y0−f^(x0)]2=Var(f^(x0))+Bias(f^(x0))2+Var(ϵ)E[y_0 - \hat{f}(x_0)]^2 = \text{Var}(\hat{f}(x_0)) + \text{Bias}(\hat{f}(x_0))^2 + \text{Var}(\epsilon) where:

  • E[y0−f^(x0)]2E[y_0 - \hat{f}(x_0)]^2 is the expected squared error on a new observation (x0,y0)(x_0, y_0).
  • Var(f^(x0))\text{Var}(\hat{f}(x_0)) is the variance of the model's prediction.
  • Bias(f^(x0))2\text{Bias}(\hat{f}(x_0))^2 is the squared bias of the model's prediction.
  • Var(ϵ)\text{Var}(\epsilon) is the irreducible error.

Trade-off: Increasing model flexibility typically decreases bias but increases variance. Conversely, decreasing flexibility increases bias but decreases variance. The goal is to find a balance that minimizes the total test error.

Model FlexibilityBiasVarianceTraining ErrorTest Error
LowHighLowHighHigh (underfitting)
MediumMediumMediumMediumOptimal (good fit)
HighLowHighLowHigh (overfitting)

3.4 Model flexibility and accuracy

Model flexibility influences prediction accuracy through the bias-variance trade-off.

  • Linear Models: Generally have low flexibility, leading to higher bias but lower variance. They are easier to interpret.
  • Non-parametric Models (e.g., Smoothing Splines): Have high flexibility, leading to lower bias but higher variance. They can capture complex patterns but are harder to interpret.

The relationship between flexibility and error is often visualized as a U-shaped curve for test error.

  • Training error consistently decreases as flexibility increases.
  • Test error initially decreases with increased flexibility (reducing bias) but then increases (due to rising variance).

Key insight: The "sweet spot" for model accuracy is where the test error is minimized, representing the best balance of bias and variance.

A 3D scatter plot showing the relationship between years of education, seniority, and income, with a regression plane fitted to the data.

A 3D surface plot showing the relationship between years of education, seniority, and income, with individual data points overlaid.

3.5 Classification problems

In classification, the response variable is qualitative.

  • Goals:
  • Build a classifier C^(X)\hat{C}(X) to assign a class label to new observations.
  • Assess the uncertainty in each classification.
  • Understand the role of predictors.
  • Conditional Class Probabilities: pk(x)=P(Y=k∣X=x)p_k(x) = P(Y=k | X=x) represents the probability of class kk given predictor values xx.
  • Bayes Optimal Classifier: Assigns an observation xx to the class jj that maximizes the conditional class probability pj(x)p_j(x). This classifier has the smallest possible error rate in the population.
  • Misclassification Error Rate: The proportion of incorrect classifications on a test set. ErrTe=Avei∈TeI(yi≠C^(xi))\text{Err}_{Te} = \text{Ave}_{i \in Te} \mathbb{I}(y_i \neq \hat{C}(x_i)) where I(⋅)\mathbb{I}(\cdot) is the indicator function.

Key point: The Bayes classifier provides a theoretical benchmark for optimal classification performance.

This scatter plot visualizes the decision boundaries of a K-Nearest Neighbors (KNN) algorithm with K=10, showing two classes of data points and their separation.

3.6 K-Nearest Neighbors (KNN) for classification

KNN is a non-parametric method that classifies a new observation based on the majority class among its KK nearest neighbors in the training data.

  • Small KK: Results in a flexible decision boundary, low bias, and high variance (prone to overfitting).
  • Large KK: Results in a smoother, less flexible decision boundary, high bias, and low variance (prone to underfitting).

Decision: The choice of KK in KNN directly impacts the bias-variance trade-off and the resulting decision boundary.

🔑 Important: A small KK in KNN leads to a more flexible boundary with low bias and high variance, while a large KK leads to a smoother boundary with high bias and low variance.

3.7 Model comparison: flexibility vs. interpretability

Different models offer varying degrees of flexibility and interpretability.

ModelInterpretabilityFlexibility
Subset Selection LassoHighLow
Generalized Additive ModelsMediumMedium
Support Vector MachinesLowHigh

🔑 Important: There is a fundamental trade-off between model interpretability and flexibility, influencing model choice based on the problem's needs.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also