1. LPU MCA Semester 1
  2. CAB107
  3. Unit 4

CAB107 · Unit 4: Machine learning fundamentals

Accuracy, precision, recall, F1-score and ROC-AUC

10 practice questions · in the ETE syllabus

Key points

  • Precision = TP/(TP+FP), recall = TP/(TP+FN)
  • F1 is the harmonic mean of precision and recall
  • Accuracy misleads on imbalanced data
  • ROC plots TPR against FPR; AUC 0.5 is chance

All classification metrics start from the confusion matrix: true positives (TP), false positives (FP), true negatives (TN) and false negatives (FN).

MetricFormulaMeaning
Accuracy(TP + TN) / totalShare of correct predictions
PrecisionTP / (TP + FP)Of predicted positives, how many are real
RecallTP / (TP + FN)Of real positives, how many are found
F12PR / (P + R)Harmonic mean of precision and recall

Worked example: TP = 40, FP = 10, FN = 20, TN = 30. Precision = 40/50 = 0.80, recall = 40/60 = 0.667, F1 = 2 x 0.8 x 0.667 / 1.467 = 0.727, accuracy = 70/100 = 0.70.

The accuracy paradox: on imbalanced data a model that always predicts the majority class can reach high accuracy while finding no positives. Use precision, recall and F1 instead.

The ROC curve plots the true positive rate against the false positive rate across thresholds. AUC is the probability that a randomly chosen positive example is scored higher than a randomly chosen negative one; 0.5 is chance level and 1.0 is perfect ranking.

Exam trap: F1 is the harmonic mean, not the arithmetic mean, and recall, not precision, is about missing real positives.

Try two questions

Question 1 · Tier 3, Apply

A confusion matrix has TP = 40, FP = 10, FN = 20 and TN = 130. What is the precision?

  1. 0.67
  2. 0.85
  3. 0.80
  4. 0.57
Show the answer

C. Precision = 40 / (40 + 10) = 0.80.

Why not A: 0.67 is the recall, 40 / 60.

Why not B: 0.85 is the accuracy, 170 / 200.

Why not D: 0.57 does not match the precision formula.

Question 2 · Tier 4, Analyse

Compute the F1-score, to two decimals, for a model with TP = 40, FP = 10, FN = 20 and TN = 130.

  1. 0.73
  2. 0.74
  3. 0.67
  4. 0.80
Show the answer

A. F1 = 2 x 0.80 x 0.667 / (0.80 + 0.667) = 0.73.

Why not B: 0.74 does not follow from the harmonic mean formula.

Why not C: 0.67 is the recall.

Why not D: 0.80 is the precision.