Skip to content
ComputerCS
Start learning

Data Analytics · Lesson 5.3

Building Statistical Models

Understand the purpose of statistical modelling, distinguish prediction and clustering, and evaluate model quality without confusing correlation with causation.

01

Learning objectives

  • Explain why a statistical model is a simplified representation of data relationships.
  • Distinguish regression, classification and clustering tasks.
  • Identify training and testing data and the risk of overfitting.
  • Interpret basic model evaluation measures and communicate uncertainty.
02

Lesson notes

A statistical model describes a relationship or pattern in data and uses it to estimate, explain or predict outcomes. A model is not the world itself: it depends on assumptions, variables, sampling and the quality of the observations. A good model should be useful for its stated purpose and evaluated on data that was not used to fit it.

Regression predicts a numerical quantity, such as estimated travel time. Classification predicts a category, such as whether a message is spam. Clustering groups observations based on similarity when predefined labels are not supplied. Linear regression models a numerical outcome using a linear relationship; logistic regression is commonly used for classification probabilities; K-means is a clustering method.

The training dataset is used to fit model parameters. A separate test dataset estimates how well the model generalises to unseen observations. Overfitting occurs when a model learns noise or quirks in its training sample rather than a stable pattern. A very high training score alongside weak test performance is a warning sign.

Model evaluation depends on the task. Mean absolute error measures average absolute prediction error for numerical outcomes. Accuracy measures the fraction of correct classifications but can mislead when classes are imbalanced. Confusion matrices expose false positives and false negatives. Ethical evaluation also asks whether a model disadvantages groups, leaks personal information or is used beyond its validated purpose.

03

Worked code examples

Worked example

The mean absolute error summarises average absolute prediction error for a regression task; it does not establish that the model is fair or causal.

actual = [10, 12, 15, 18]
predicted = [11, 11, 14, 20]
mae = sum(abs(a - p) for a, p in zip(actual, predicted)) / len(actual)
print("Mean absolute error:", mae)
Output
Mean absolute error: 1.5
04

Key terminology

Regression

A modelling task that predicts a numerical value.

Classification

A modelling task that predicts a category or class.

Clustering

Grouping observations by similarity without supplied class labels.

Overfitting

A model fitting training noise and generalising poorly to new data.

05

Common misconceptions

Common mistake

A strong training score proves a model generalises.

Correct understanding

Generalisation must be evaluated on separate data that was not used to fit the model.

Common mistake

Correlation proves that one variable causes another.

Correct understanding

Correlation indicates association; causal claims require stronger design and evidence.

06

Check your understanding

1. Which task predicts a numerical house price?

2. What is overfitting?

3. Why keep a separate test dataset?

NERDLYY · FEEDBACK

Help shape Nerdlyy

Your feedback goes directly to the team. We read every submission.

No reply needed — you can send feedback without sharing contact details.