IB Computer Science HL · Year 2 · Lesson 52

Regression, classification and model evaluation

Predict continuous or categorical outcomes, calculate evaluation metrics and explain hyperparameter choices.

Paper 150 minutesA4.3.1 · A4.3.2 · A4.3.3
Targets

What you need to be able to do

2 / 11
  • explain linear regression using predictor/response, slope, intercept and R²;
  • explain K-NN and decision-tree classification from labelled data;
  • calculate and interpret accuracy, precision, recall and F1;
  • explain how hyperparameter tuning can lead toward overfitting or underfitting.
A4.3.1A4.3.2A4.3.3
Learn + retrieve

Rapid Recall Deck

3 / 11

Attempt each card first. If a term is new, flip and study it, then answer it again without looking. Mark only secure recall as “Know it”.

A4.3.1 · Explain

Read a regression equation

4 / 11

Energy-use model

predicted_kWh = 120 + 8 × hours_used

Identify predictor and response, then interpret slope 8 and intercept 120.

Predictor: hours_used. Response: predicted kWh. The model predicts about 8 additional kWh for each extra hour-used unit. The intercept predicts 120 kWh at hours_used=0; that interpretation is only meaningful if zero is sensible for the data/context.

Regression + classification

Choose the output type

5 / 11

R²

Model A has R²=0.82 and Model B has R²=0.31 on comparable evaluation data. What can you cautiously infer?

Model A explains more observed response variation through its fitted relationship. R² alone does not prove causation, fairness or overall suitability.

Regression or classification?

House price; benign/malignant tumour; tomorrow's temperature; spam/not spam.

Regression, classification, regression, classification.

A4.3.2 · Explain

K-NN and decision trees

6 / 11

K-NN

A new user's five nearest labelled neighbours contain four “liked” and one “disliked”. Under majority voting, predict and explain.

Predict “liked”. K-NN compares the new point to labelled training examples, selects K nearby examples and derives the category from their labels.

Decision tree

Why can symptom-based medical diagnosis fit a decision tree?

The tree can learn symptom/feature splits from labelled cases and apply a sequence of conditions to reach a categorical diagnosis. Tree complexity still needs tuning.

K-NN may also support collaborative-filtering recommendation scenarios because similarity among users/items can guide predictions.
A4.3.3

Calculate evaluation metrics

7 / 11

Confusion matrix

Actual +Actual −
Predicted +TP=40FP=10
Predicted −FN=20TN=130

Calculate accuracy, precision and recall.

Accuracy=(40+130)/200=0.85. Precision=40/(40+10)=0.80. Recall=40/(40+20)≈0.667.

F1 + metric choice

The cost of errors changes the useful metric

8 / 11

F1

Use precision 0.80 and recall 0.667.

F1 = 2 × precision × recall / (precision + recall)

F1≈0.727.

Medical screening

If missing a true disease case is especially harmful, which metric deserves strong attention?

Recall, because it measures the proportion of actual positive cases correctly identified; low recall means many false negatives.

Hyperparameters

Generalization rather than memorization

9 / 11

K too small / too large

Explain the overfit/underfit risk in K-NN.

Very small K can be sensitive to noise and overfit; very large K can smooth away useful local structure and underfit. Validation evidence helps choose K.

Training vs validation

99% training, 72% validation versus 61% training, 59% validation. Diagnose each.

99/72 suggests overfitting. 61/59 suggests underfitting. Tuning model complexity, features and training settings should target better generalization.

Exam lens + case transfer

Metrics must fit the real outcome

10 / 11

Paper 1 mini-set

1. Precision=.75, recall=.60: calculate F1. 2. Explain how K-NN predicts a category. 3. Explain hyperparameter tuning and overfitting.

F1≈0.667. K-NN uses labels of nearby examples under a distance/K rule. Hyperparameters control model/training behaviour; validation-based tuning helps avoid settings that memorize training noise.

Visionary Studios

Why is “highest accuracy” not a sufficient model-selection rule for its generative-image system?

The case requires output quality, computational efficiency, training stability, flexibility/scalability and consistency—not one classification-accuracy score. Selection must use evidence aligned to those outcomes.

Homework

Finish the learning cycle

11 / 11

Case study / exam preparation

Add evidence to the Visionary Studios model-comparison matrix using the official evaluation factors.

Paper 1 — short practice

Recalculate accuracy, precision, recall and F1 on two small confusion matrices.

Case-study checkpoint

Explain one overfitting and one underfitting diagnosis without notes.