Why does statistics matter in machine learning?

  • A predictive model learns patterns from past observations.
  • Statistics helps us describe relationships, estimate unknown quantities, and measure uncertainty.
  • Running example: Can study habits help predict an exam score?

Main idea: Good predictions require both a useful model and honest evaluation.

Our example dataset

We simulate data for 120 students. Each observation has:

  • Study hours: time spent reviewing before an exam.
  • Practice problems: number of problems completed.
  • Exam score: result on a 0–100 scale.

The dataset is synthetic, created only to demonstrate statistical methods. It does not establish a causal effect.

First look: study hours and scores

Distribution of model errors

Interactive view: two predictors and the score

Rotate or zoom the 3D points to inspect how the two predictors relate to exam scores.

Linear regression: a statistical model

A multiple linear regression combines both predictors:

\[ \widehat{y}_i = \widehat{\beta}_0 + \widehat{\beta}_1 x_{i1} + \widehat{\beta}_2 x_{i2} \]

Here, \(\widehat{y}_i\) is the predicted score, \(x_{i1}\) is study hours, and \(x_{i2}\) is practice problems.

The coefficients are estimated by minimizing the sum of squared residuals:

\[ \min_{\beta_0,\beta_1,\beta_2} \sum_{i=1}^{n}(y_i-\beta_0-\beta_1x_{i1}-\beta_2x_{i2})^2 \]

Interpreting our fitted model

  • Intercept: 31.04 points (a model baseline).
  • Study hours: +5.24 points per hour, holding practice problems fixed.
  • Practice problems: +0.26 points per additional problem, holding study hours fixed.
  • Explained variance: \(R^2 = 0.733\) in this simulated dataset.

These are associations from simulated observations, not proof of cause and effect.

Quantifying accuracy with RMSE

A residual is the difference between observed and predicted scores:

\[e_i = y_i - \widehat{y}_i\]

Root mean squared error summarizes typical prediction error in score points:

\[ \mathrm{RMSE} = \sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_i-\widehat{y}_i)^2} \]

Training-set RMSE: 7.75 score points.

This is an in-sample result; a held-out test set would better measure performance on new students.

R code: fitting and checking a model

The following is the core R workflow used in this presentation:

# Fit a regression model using the simulated data
model <- lm(exam_score ~ study_hours + practice_problems,
            data = students)

# Compute fitted values and training residuals
predicted <- predict(model, newdata = students)
errors <- students$exam_score - predicted
rmse <- sqrt(mean(errors^2))

summary(model)
rmse

Key takeaways

  • Visualization helps uncover possible trends and outliers.
  • Regression summarizes the relationship between predictors and outcomes.
  • Residuals and RMSE help assess model fit.
  • Validation on unseen data is necessary before trusting real-world predictions.

Bottom line: Statistics provides the tools to make predictive models interpretable and testable.