🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Model Evaluation: ROC, AUC, Precision, Recall and F1

Module 7: Machine Learning FundamentalsModel Evaluation🟢 Free Lesson

Advertisement

Why Model Evaluation Matters

A model is only as good as our ability to measure its performance. Choosing the wrong metric can lead to catastrophically poor deployment decisions. This lesson covers the essential evaluation toolkit every ML practitioner must master.


1. The Confusion Matrix

For a binary classifier, the confusion matrix partitions predictions into four categories:

Predicted PositivePredicted Negative
Actual PositiveTrue Positive (TP)False Negative (FN)
Actual NegativeFalse Positive (FP)True Negative (TN)
Confusion Matrix
Predicted Positive
Predicted Negative
Actual Positive
Actual Negative
TP
True Positive
Correctly predicted positive
FN
False Negative
Missed positive (Type II)
FP
False Positive
False alarm (Type I)
TN
True Negative
Correctly predicted negative
?� Correct predictions ?�
?� Errors ?�

Key Definitions

  • Positive class = the class of interest (e.g., "has cancer", "fraudulent transaction")
  • TP: Model predicts positive, actual is positive
  • FP: Model predicts positive, actual is negative (Type I error)
  • FN: Model predicts negative, actual is positive (Type II error)
  • TN: Model predicts negative, actual is negative

⚠️

The choice of which class is "positive" is arbitrary but critical. In disease screening, the diseased class is typically positive. Changing this flips TP?�TN and FP?�FN.


2. Classification Metrics

2.1 Accuracy

The fraction of all predictions that are correct. Dangerous when classes are imbalanced. A model predicting "no cancer" for all patients in a population with 1% prevalence achieves 99% accuracy while being completely useless.

2.2 Precision (Positive Predictive Value)

Of all instances the model predicted as positive, what fraction actually are positive? High precision means few false alarms.

Use when: False positives are costly (e.g., spam filter marking legitimate emails as spam).

2.3 Recall (Sensitivity, True Positive Rate)

Of all actual positive instances, what fraction did the model catch? High recall means few missed positives.

Use when: False negatives are costly (e.g., failing to detect cancer).

2.4 F1-Score

The harmonic mean of precision and recall. Balances both concerns. The harmonic mean penalizes extreme imbalances more than the arithmetic mean.

2.5 Fβ-Score (Generalized)

  • : Equal weight (standard F1)
  • : Recall weighted 2× more than precision
  • : Precision weighted 2× more than recall

Comparison Table

MetricRangeBest WhenWeakness
Accuracy[0, 1]Balanced classesMisleading with imbalance
Precision[0, 1]FP costlyIgnores FN
Recall[0, 1]FN costlyIgnores FP
F1[0, 1]Balanced needIgnores TN

ℹ️

Multi-class extensions: For K classes, compute precision, recall, F1 per class, then aggregate:

  • Macro-average: Unweighted mean across classes (treats all classes equally)
  • Micro-average: Aggregate TP, FP, FN globally, then compute (biased toward majority class)
  • Weighted-average: Weighted by class support (number of instances per class)

3. The ROC Curve

3.1 Concept

The Receiver Operating Characteristic (ROC) curve plots the tradeoff between catching positives and raising false alarms as the classification threshold varies.

For each possible threshold :

  1. Classify instances with score ��¥ as positive
  2. Compute (FPR, TPR) pair
  3. Plot the curve
False Positive Rate (FPR)True Positive Rate (TPR)00.250.50.751.000.250.50.751.0Random (AUC = 0.5)Good model (AUC �� 0.92)Perfect (AUC = 1.0)ROC Curve

3.2 Interpreting the ROC Curve

  • Top-left corner (0, 1): Perfect classifier — catches all positives with no false alarms
  • Diagonal line: Random guessing — no discriminative power
  • Below diagonal: Worse than random (usually indicates flipped labels)
  • Closer to top-left: Better model

3.3 Threshold Selection

The ROC curve does not tell you which threshold to use. Common strategies:

  1. Closest to (0, 1): Minimize
  2. Youden's J statistic: Maximize
  3. Cost-based: Assign costs to FP and FN, minimize expected cost

4. AUC — Area Under the ROC Curve

Equivalently, AUC is the probability that a randomly chosen positive instance is ranked higher than a randomly chosen negative instance:

AUC Interpretation

AUC RangeInterpretation
0.90 – 1.00Excellent
0.80 – 0.90Good
0.70 – 0.80Fair
0.60 – 0.70Poor
0.50 – 0.60Fail (no better than random)

AUC is threshold-invariant: It evaluates the model's ranking ability across all thresholds simultaneously.

AUC is class-prevalence-invariant: Unlike accuracy, it doesn't change when class proportions shift.

⚠️

AUC can be misleading with severe class imbalance. A model with AUC = 0.95 may still have poor precision at the operating point needed for deployment. Always examine the ROC curve itself, not just the single AUC number.


5. Precision-Recall (PR) Curve

When the positive class is rare, the PR curve provides a more informative view than ROC.

The PR curve plots Precision (y-axis) vs. Recall (x-axis) across all thresholds.

RecallPrecision00.250.50.751.000.250.50.751.0Baseline (prevalence = 0.1)Good model (AP �� 0.88)Poor model (AP �� 0.35)Precision-Recall Curve

Average Precision (AP)

where and are recall and precision at the -th threshold. AP summarizes the PR curve into a single number (area under the PR curve).

When to Use PR vs. ROC

ScenarioPrefer
Balanced classesROC
Severe imbalance (positive class rare)PR
Both classes matter equallyROC
False positives very costlyPR
False negatives very costlyROC (or PR with recall focus)

6. Regression Metrics

6.1 Mean Squared Error (MSE)

Penalizes large errors quadratically. Sensitive to outliers. Units are squared.

6.2 Root Mean Squared Error (RMSE)

Same units as the target variable. More interpretable than MSE.

6.3 Mean Absolute Error (MAE)

Robust to outliers. Linear penalty for errors.

6.4 R² (Coefficient of Determination)

  • : Perfect prediction
  • : Model performs no better than predicting the mean
  • : Model is worse than the mean

Metric Comparison

MetricSensitive to OutliersInterpretable UnitsPenalizes Large Errors
MSEYes (quadratic)No (squared)Strongly
RMSEYes (quadratic)YesStrongly
MAENo (linear)YesLinearly
DependsNo (normalized)Relative

ℹ️

Adjusted R² penalizes model complexity: , where is the number of predictors. Use this to compare models with different numbers of features.


7. Bias-Variance Tradeoff

The expected prediction error for a model can be decomposed as:

Bias-Variance Decomposition
Target (true value)
High Bias, Low Variance
Underfitting
Low Bias, High Variance
Overfitting
Low Bias, Low Variance
Good Fit
Model Complexity ?�
Simple
Complex

Definitions

Bias (systematic error): Error from erroneous assumptions in the learning algorithm. High bias causes the model to miss relevant relations between features and targets.

Variance (sensitivity to data): Error from sensitivity to small fluctuations in the training set. High variance causes the model to model random noise.

The Tradeoff

  • Increasing model complexity ?� decreases bias, increases variance
  • Decreasing model complexity ?� increases bias, decreases variance
  • Optimal complexity ?� minimizes total error

Practical Implications

SymptomDiagnosisRemedies
High training errorHigh bias (underfitting)More features, more complex model, reduce regularization
Low training error, high test errorHigh variance (overfitting)More data, regularization, ensemble methods, feature selection
High training and test errorVery high biasFundamentally wrong model class

8. Learning Curves

Learning curves plot model performance as a function of training set size, revealing whether the model suffers from bias, variance, or both.

Learning CurvesTraining Set SizeError0LowMedHighTraining errorValidation errorGapHigh Variance (Overfitting)Large gap, training error low Learning Curves — High BiasTraining Set SizeErrorTraining errorValidation errorSmall gapHigh Bias (Underfitting)Both errors high, small gap

Reading Learning Curves

High Variance (overfitting):

  • Training error: Low and stays low
  • Validation error: Starts high, slowly decreases
  • Large gap between curves
  • Fix: More data, regularization, simpler model, feature reduction

High Bias (underfitting):

  • Training error: Starts moderate, stays moderate/high
  • Validation error: Starts high, converges toward training error
  • Small gap, both converge to high error
  • Fix: More complex model, more features, reduce regularization

The Irreducible Error

Both curves converge to a floor above zero — this is the irreducible error (), the noise inherent in the data that no model can eliminate.


9. Summary Table

MetricTypeBest ForSensitive to Imbalance?
AccuracyClassificationBalanced classesYes (misleading)
PrecisionClassificationFP costlyNo
RecallClassificationFN costlyNo
F1-ScoreClassificationBalanced P/RModerate
AUC-ROCClassificationRanking qualityNo
AP / AUC-PRClassificationImbalanced positive classNo
MSE/RMSERegressionLarge error penaltyN/A
MAERegressionRobust to outliersN/A
RegressionVariance explainedN/A

10. Key Takeaways

  1. Never use accuracy alone with imbalanced classes — use precision, recall, F1, or AUC.
  2. ROC curves show the full threshold tradeoff; AUC summarizes ranking ability.
  3. PR curves are more informative than ROC when the positive class is rare.
  4. Bias-variance decomposition diagnoses underfitting vs. overfitting.
  5. Learning curves reveal whether more data or a more complex model will help.
  6. Choose metrics aligned with business costs — what matters more: false alarms or missed detections?

ℹ️

Next up: Module 8 covers hyperparameter tuning and model selection — how to systematically optimize the models you've learned to evaluate.

Need Expert Data Science Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement