Introduction to Data Science

Chapter 11
Model Evaluation, Interpretation and Reliability

Diploma in Data science
Introduction to Data Science   •   Diploma

Model Evaluation, Interpretation and Reliability

Introduction

Building a predictive model is only one part of data science. A model may produce predictions, but the central professional question is whether those predictions are sufficiently accurate, reliable, interpretable and appropriate for the intended decision. A model that performs well on historical training data may fail on new observations. Another model may achieve high overall accuracy while performing poorly for a minority group. A third may be statistically accurate but impossible to justify to users or regulators.

Model evaluation provides evidence about performance. Model interpretation explains how and why predictions are produced. Reliability concerns the extent to which reported performance and model behaviour can be trusted across new data, populations and operating conditions. These ideas are closely connected: an evaluation method that leaks information can make a model appear reliable when it is not, while an interpretation method that is mistaken for causal analysis can lead to harmful decisions.

This chapter develops practical foundations for evaluating classification and regression models, diagnosing underfitting and overfitting, addressing class imbalance, applying cross-validation and using introductory interpretation techniques.

Learning Objectives

By the end of this chapter, you should be able to:

  • distinguish training, validation and test performance;
  • select suitable classification and regression metrics;
  • construct and interpret a confusion matrix;
  • recognize underfitting, overfitting and class imbalance;
  • apply cross-validation without contaminating evaluation data;
  • explain the difference between global and local model interpretation;
  • identify important limitations, fairness concerns and governance requirements;
  • assess whether a reported model result is sufficiently reliable for a practical use case.

1. What Makes Model Evaluation Reliable?

A model is trained using data containing input variables and, in supervised learning, a target variable. Let the input vector be x and the target be y. A fitted model produces a prediction \hat{y} = f(x). Evaluation compares predictions with appropriate reference values, usually observed outcomes.

A reliable evaluation should answer four questions:

  1. Does the model generalize? It should perform well on previously unseen data drawn from the intended population.
  2. Is the metric appropriate? The measure must reflect the task and the cost of errors.
  3. Is performance stable? Results should not depend excessively on one random train–test split.
  4. Can the result be interpreted responsibly? The model should be understood sufficiently for its context, limitations and risks.

Training, validation and test data

A common workflow divides data into:

  • Training data: used to estimate model parameters.
  • Validation data: used to select models, hyperparameters or decision thresholds.
  • Test data: held back until final evaluation.

The test set must not influence model selection. Repeatedly checking the test set and choosing the best result effectively turns it into validation data, causing optimistic bias. In a simple split, a dataset might be divided into 70% training, 15% validation and 15% test data, although the proportions depend on dataset size and task requirements.

Data preprocessing can also cause leakage. For example, calculating a scaling mean using all observations before splitting allows information from the test set to enter training. The correct procedure is to fit preprocessing only on training data and apply the learned transformation to validation and test observations.

2. Classification Evaluation

Classification predicts a discrete class, such as fraudulent/not fraudulent or disease/no disease. For binary classification, one class is designated positive and the other negative. A prediction can therefore be categorized as follows:

Actual conditionPredicted positivePredicted negative
PositiveTrue positive (TP)False negative (FN)
NegativeFalse positive (FP)True negative (TN)

A true positive is a correctly identified positive case. A false positive is a negative case incorrectly classified as positive. A false negative is a missed positive case. A true negative is a correctly rejected negative case.

Accuracy

Accuracy is the proportion of all predictions that are correct:

Accuracy = (TP + TN) ÷ (TP + TN + FP + FN)

The denominator is the total number of observations. Accuracy is useful when classes are reasonably balanced and the costs of false positives and false negatives are similar. It can be misleading with imbalanced data.

Precision and recall

Precision measures the reliability of positive predictions:

Precision = TP ÷ (TP + FP)

Recall, also called sensitivity or true positive rate, measures the proportion of actual positives detected:

Recall = TP ÷ (TP + FN)

Precision is especially important when false alarms are costly. Recall is especially important when missing a positive case is dangerous, as in screening for a serious disease.

The F1 score is the harmonic mean of precision and recall:

F1 = 2 × (Precision × Recall) ÷ (Precision + Recall)

It is defined when precision plus recall is greater than zero. The harmonic mean gives a low score when either component is low. F1 is useful when both types of error matter, but it does not directly account for true negatives or financial costs.

Specificity and related rates

Specificity, or true negative rate, measures the proportion of actual negatives correctly identified:

Specificity = TN ÷ (TN + FP)

The false positive rate is:

FPR = FP ÷ (FP + TN) = 1 − Specificity

The false negative rate is:

FNR = FN ÷ (FN + TP) = 1 − Recall

All denominators must be non-zero. These measures describe different aspects of performance and should not be treated as interchangeable.

Worked example: interpreting a confusion matrix

Suppose a fraud detector produces the following results for 1,000 transactions:

  • TP = 72
  • FN = 8
  • FP = 40
  • TN = 880

Then:

Accuracy = (72 + 880) ÷ 1,000 = 0.952 = 95.2%
Precision = 72 ÷ (72 + 40) = 72 ÷ 112 ≈ 64.3%
Recall = 72 ÷ (72 + 8) = 72 ÷ 80 = 90%

The detector finds most fraudulent transactions, but only about 64.3% of transactions flagged as fraud are actually fraudulent. Whether this is acceptable depends on the investigation cost and the harm caused by missed fraud.

Thresholds and probability predictions

Many classifiers produce a probability estimate rather than a class directly. A threshold converts the probability into a label. With a threshold of 0.5, an observation may be classified positive when its estimated probability is at least 0.5. Lowering the threshold generally increases recall and false positive rate, while raising it generally decreases them. The best threshold should be selected using validation data and an explicit operational objective, not automatically assumed to be 0.5.

ROC and precision–recall curves

A receiver operating characteristic (ROC) curve displays true positive rate against false positive rate over many thresholds. The area under this curve, ROC–AUC, measures ranking ability: it can be interpreted as the probability that a randomly selected positive observation receives a higher score than a randomly selected negative observation, subject to standard tie-handling conventions.

ROC–AUC can appear strong when the negative class is very large. For rare positive events, a precision–recall curve often gives a more informative view because it emphasizes precision and recall. Neither curve alone specifies the business cost of errors or guarantees good probability calibration.

Log loss and calibration

When predicted probabilities are important, log loss evaluates the quality of those probabilities. For binary outcomes yi ∈ {0,1} and predicted probabilities pi, the mean log loss is:

Log loss = −(1 ÷ n) ∑[i=1 to n] [yi ln(pi) + (1 − yi) ln(1 − pi)]

Here, n is the number of observations and ln is the natural logarithm. Predictions of exactly 0 or 1 require careful numerical handling because ln(0) is undefined. Log loss penalizes confident incorrect predictions strongly.

A classifier is calibrated if, among cases assigned a probability of approximately 0.7, about 70% are positive in the relevant population. Calibration is different from discrimination. A model can rank cases well but provide poorly calibrated probabilities.

3. Regression Evaluation

Regression predicts a numerical quantity, such as energy use, sales or delivery time. Let yi be the observed value and \hat{y}i the prediction for observation i. The residual is:

ei = yi − \hat{y}i

A positive residual means the model underpredicted; a negative residual means it overpredicted.

Mean absolute error

MAE = (1 ÷ n) ∑[i=1 to n] |yi − \hat{y}i|

MAE is expressed in the same units as the target and represents average absolute prediction error. It is relatively easy to explain and less sensitive to extreme errors than squared-error measures.

Mean squared error and root mean squared error

MSE = (1 ÷ n) ∑[i=1 to n] (yi − \hat{y}i)²
RMSE = √MSE

MSE has squared target units, while RMSE returns to the original units. Because errors are squared, large errors receive disproportionately high weight. RMSE is useful when large deviations are particularly undesirable.

Coefficient of determination

A commonly used measure is:

R² = 1 − [∑(yi − \hat{y}i)² ÷ ∑(yi − ȳ)²]

Here, ȳ is the mean of observed target values. The denominator is the total sum of squares, representing variation around the mean. R² compares the model with a baseline that always predicts the training or evaluation mean, depending on the context. It can be negative on test data when the model performs worse than that baseline. R² is not the proportion of individual predictions that are correct, and a high value does not prove that the model is useful.

Worked example: regression metrics

For observed values [10, 12, 15] and predictions [11, 10, 14], residuals are [−1, 2, 1]. Therefore:

MAE = (1 + 2 + 1) ÷ 3 = 1.33
MSE = (1² + 2² + 1²) ÷ 3 = 2
RMSE = √2 ≈ 1.41

The MAE and RMSE are measured in the units of the target, while MSE is measured in squared units. Metric selection should reflect the consequences of error, not merely the desire for a higher score.

Percentage-based measures such as mean absolute percentage error can be difficult when actual values are zero or close to zero. Always inspect the target scale and the distribution of errors. Residual plots can reveal non-linearity, changing variance or systematic bias that a single metric conceals.

4. Underfitting, Overfitting and the Bias–Variance Trade-off

Underfitting occurs when a model is too simple to represent important patterns. It generally has high training error and high validation error. For example, a straight-line model may underfit a strongly curved relationship.

Overfitting occurs when a model learns random noise or peculiarities of the training sample. It usually has very low training error but substantially higher validation or test error. Highly complex trees, excessive feature engineering and repeated tuning against a small validation set can encourage overfitting.

The bias–variance trade-off provides a useful conceptual framework. Bias is systematic error from restrictive assumptions; variance is sensitivity to the particular training sample. Increasing complexity may reduce bias but increase variance. Regularization, simpler models, more data, feature selection and early stopping can help control overfitting.

A learning curve plots training and validation performance against training-set size or model complexity. The pattern of the two curves is often more informative than a single score. Diagnosis should also consider data quality, distribution shift and measurement error; not every performance gap is caused by model complexity.

5. Class Imbalance and Fair Evaluation

Class imbalance occurs when one class is much more frequent than another. If only 1% of transactions are fraudulent, a classifier that always predicts “not fraud” achieves 99% accuracy but has zero recall for fraud. This is why the majority-class baseline must be reported.

Useful responses include:

  • reporting precision, recall, specificity and a confusion matrix;
  • using stratified splitting so class proportions are approximately preserved;
  • selecting thresholds according to error costs;
  • applying class weights or resampling within training folds;
  • examining performance separately for relevant subgroups;
  • using precision–recall analysis for rare positive events.

Oversampling or undersampling must be performed only on the training portion of each fold. Resampling before cross-validation can place duplicate or related observations in both training and validation data, producing an overoptimistic result.

Fairness analysis asks whether errors and benefits are distributed appropriately across groups. Important measures may include group-specific recall, false positive rate, precision and calibration. These measures can conflict mathematically when base rates differ, so there is no universal fairness metric that resolves every policy question. A professional evaluation should identify affected groups, justify the selected criteria and document trade-offs.

6. Cross-Validation

Cross-validation estimates how a model may perform on unseen data by repeatedly dividing the available development data into training and validation portions. In k-fold cross-validation, the data are divided into k folds. Each fold is used once as validation data while the remaining k − 1 folds are used for training. The reported score is commonly the mean of the k validation scores:

Mean CV score = (1 ÷ k) ∑[j=1 to k] Scorej

A sample standard deviation may also be reported:

s = √{[1 ÷ (k − 1)] ∑[j=1 to k] (Scorej − Mean CV score)²}

Here, Scorej is the score from fold j. The standard deviation describes variation across folds, not a complete confidence interval for future performance.

Common forms include:

  • Stratified k-fold: preserves class proportions for classification.
  • Repeated k-fold: repeats the process with different partitions to assess stability.
  • Leave-one-out: uses one observation for validation at a time; it can be computationally expensive and may have high variance.
  • Group cross-validation: keeps observations from the same person, household or organisation in one fold.
  • Time-series validation: trains on earlier observations and validates on later observations, respecting temporal order.

Cross-validation is not a substitute for a final untouched test set when sufficient data are available. A sound workflow uses cross-validation for model and hyperparameter selection, then evaluates the selected process once on the test set. All feature selection, imputation, scaling and resampling should occur inside the cross-validation pipeline.

7. Model Interpretation

Interpretation methods help users understand relationships between inputs and predictions. They do not automatically establish causation. A feature may be predictive because it is associated with an unmeasured cause, acts as a proxy for a sensitive attribute or reflects data collection practices.

Coefficients and simple models

In linear regression, a coefficient describes the expected change in the predicted target for a one-unit increase in a feature, holding the other included features constant, under the model assumptions. Interpretation becomes difficult when features are highly correlated, measured on different scales or related non-linearly. Logistic regression coefficients operate on log-odds, so they should not be casually interpreted as direct probability changes.

Feature importance

Tree-based models often provide impurity-based feature importance, but this can favour high-cardinality or continuous variables and can distribute importance unpredictably among correlated features. Permutation importance measures the performance decrease after a feature’s values are shuffled. It is more directly related to predictive usefulness, but correlated features can make the result unstable.

Partial dependence and local explanations

A partial dependence plot estimates the average model prediction as one feature varies while other features are averaged over the data. It can be misleading when the varied feature combinations are unrealistic or outside the observed joint distribution.

Local explanation methods, such as additive contribution approaches, describe why one particular prediction differs from a reference prediction. They are useful for case review, but explanations may be approximate, depend on the background data and should not be treated as the model’s unique “true reasoning.” A responsible interpretation report should state the method, reference population, assumptions and limitations.

8. An Applied Case: Predicting Loan Default

Background

A fictional community lender develops a model to identify applicants who may default within twelve months. The model is intended to support manual review, not automatically reject applications.

Problem

The development data contain 20,000 applications, but only 600 defaults. A preliminary model reports 97% accuracy. Management initially considers this excellent.

Analysis

The majority-class baseline already achieves 97% accuracy by predicting no default for every applicant. The preliminary result therefore provides little evidence of usefulness. The data science team constructs a confusion matrix and reports recall, precision, specificity and the precision–recall curve. Because a missed default and an unnecessary manual review have different costs, the team does not assume a 0.5 classification threshold.

The team also identifies repeated applications from the same customer. Randomly distributing these applications across folds could allow customer-specific patterns to leak between training and validation. Grouped cross-validation is therefore used. Income imputation, scaling and class weighting are fitted within each training fold. A final test set is kept untouched.

Approach and solution

Several models are compared using stratified grouped cross-validation. Performance is reported as mean and standard deviation across folds. Thresholds are selected on validation predictions using a documented cost function. Group-specific recall and false positive rates are inspected, and an adverse-action review process is designed for applicants affected by the model.

Interpretation uses permutation importance and individual case explanations. The team checks whether variables such as postcode act as proxies for protected characteristics. The model card records its intended use, training population, known limitations, monitoring plan and conditions requiring retraining.

Outcome

The final test evaluation shows lower accuracy than the original report but substantially better evidence: recall is high enough for the lender’s risk objective, precision is acceptable for the manual-review capacity, and performance is monitored across customer groups. The model is deployed as decision support rather than an autonomous decision-maker.

Learning points

The case demonstrates that a high accuracy score can be meaningless under imbalance. Reliability requires leakage prevention, appropriate validation, cost-sensitive threshold selection, subgroup analysis, interpretation and post-deployment monitoring.

9. Limitations, Governance and Monitoring

Evaluation results are conditional on the data-generating environment. Population changes, new policies, economic events, sensor failures or changes in labelling can cause data drift or concept drift. A model that was reliable at development may degrade in production.

Best practice includes:

  • defining the prediction target and evaluation population precisely;
  • comparing with simple baselines;
  • selecting metrics before examining results where possible;
  • reporting uncertainty or variation, not only a single score;
  • preserving an untouched test set;
  • documenting preprocessing, features, versions and random seeds;
  • monitoring input distributions, missingness, calibration, error rates and subgroup performance;
  • establishing human review, appeal and escalation procedures for high-impact decisions;
  • protecting personal data and limiting access to sensitive records;
  • auditing model use rather than evaluating only the model in isolation.

Privacy law, anti-discrimination law, sector regulation and institutional policy may impose obligations concerning transparency, data minimisation, explainability, retention and accountability. Technical performance does not override these obligations. A model should not be deployed merely because it outperforms an alternative if its use is unlawful, unsafe or inconsistent with the organisation’s responsibilities.

Chapter Summary

Model evaluation estimates how well a model performs on new data, while interpretation explains patterns in model behaviour and reliability concerns whether those conclusions remain trustworthy. Classification should be evaluated with metrics suited to the class distribution and error costs, including accuracy, precision, recall, specificity, F1, ROC–AUC, precision–recall analysis and calibration. Regression commonly uses MAE, MSE, RMSE and R², each providing different information.

Underfitting reflects insufficient model flexibility; overfitting reflects excessive adaptation to training data. Class imbalance makes accuracy unreliable and requires suitable baselines and class-sensitive measures. Cross-validation provides more stable development estimates, but preprocessing and resampling must occur within each training fold, and a final test set should remain untouched. Interpretation methods include coefficients, permutation importance, partial dependence and local explanations, but none automatically proves causation. Responsible deployment also requires subgroup analysis, documentation, privacy protection and monitoring for drift.

Key Terms

Accuracy: Proportion of all predictions that are correct.

Calibration: Agreement between predicted probabilities and observed frequencies.

Class imbalance: Unequal representation of classes in a classification dataset.

Confusion matrix: Table showing true and false positive and negative predictions.

Cross-validation: Repeated division of development data for model assessment and selection.

False negative: A positive case incorrectly predicted as negative.

False positive: A negative case incorrectly predicted as positive.

F1 score: Harmonic mean of precision and recall.

MAE: Mean absolute error, expressed in target units.

Overfitting: Learning training-specific noise that harms generalization.

Precision: Proportion of predicted positives that are actually positive.

Recall: Proportion of actual positives correctly detected.

Residual: Difference between an observed and predicted regression value.

RMSE: Square root of mean squared error.

Specificity: Proportion of actual negatives correctly identified.

Test set: Data held back for final unbiased evaluation.

Underfitting: Failure of an overly simple model to capture important patterns.

Validation set: Data used for model or threshold selection during development.

Review Questions

Short Answer Questions

  1. What is the difference between precision and recall?
  2. Why can accuracy be misleading for imbalanced classification data?
  3. Define overfitting and give one method for reducing it.
  4. What information does RMSE provide that MAE does not emphasize as strongly?
  5. Why should preprocessing be fitted within cross-validation folds?

Long Answer Questions

  1. Explain how a confusion matrix supports the selection of classification metrics.
  2. Compare MAE, RMSE and R², including situations in which each may be useful.
  3. Describe a correct k-fold cross-validation workflow for selecting a classification model.
  4. Explain the difference between global and local model interpretation and discuss their limitations.
  5. Discuss why a model with high test performance may still be unsuitable for deployment.

Analytical / Application Questions

  1. A disease-screening model has high accuracy but low recall. Which practical risks does this create, and which metrics or threshold changes should be investigated?
  2. A fraud dataset contains 2% fraudulent transactions. Design an evaluation plan that avoids misleading conclusions from accuracy and prevents leakage during resampling.
  3. A loan model performs differently across demographic groups. Propose a technical and governance investigation before deployment.

Multiple Choice Questions with Answers

Question 1

Which metric measures the proportion of predicted positive cases that are actually positive?

A. Recall

B. Precision

C. Specificity

D. Accuracy

Correct Answer: B. Precision

Question 2

A classifier has TP = 80 and FN = 20. What is its recall?

A. 20%

B. 50%

C. 80%

D. 100%

Correct Answer: C. 80%

Question 3

Which regression metric is expressed in the same units as the target and gives less emphasis to extreme errors than RMSE?

A. MAE

B. MSE

C. R²

D. Log loss

Correct Answer: A. MAE

Question 4

What is the principal danger of fitting a scaler using the entire dataset before cross-validation?

A. It always reduces model complexity

B. It causes information leakage

C. It guarantees underfitting

D. It removes class imbalance

Correct Answer: B. It causes information leakage

Question 5

A model has very low training error and much higher validation error. Which problem is most likely?

A. Underfitting

B. Overfitting

C. Perfect calibration

D. Class balance

Correct Answer: B. Overfitting

Question 6

Why can a majority-class baseline be important in an imbalanced classification problem?

A. It provides a comparison that may reveal misleading accuracy

B. It always gives the best recall

C. It removes the need for a test set

D. It guarantees fair predictions

Correct Answer: A. It provides a comparison that may reveal misleading accuracy

Question 7

Which cross-validation method is most appropriate when observations from the same person must not appear in both training and validation folds?

A. Random holdout only

B. Group cross-validation

C. Leave-zero-out validation

D. Unstratified bootstrap scoring

Correct Answer: B. Group cross-validation

Question 8

What does a calibrated predicted probability of approximately 0.7 ideally mean?

A. The model is correct on exactly 70% of all observations

B. The case is ranked above 70% of cases

C. About 70% of comparable cases are positive

D. The model has a 70% recall

Correct Answer: C. About 70% of comparable cases are positive

Question 9

Which statement about model interpretation is correct?

A. Feature importance automatically proves causation

B. A local explanation describes model behaviour for a particular prediction

C. Partial dependence always uses realistic feature combinations

D. Coefficients are unaffected by correlated predictors

Correct Answer: B. A local explanation describes model behaviour for a particular prediction

Question 10

For rare positive events, which curve is often especially informative because it focuses on precision and recall?

A. Precision–recall curve

B. Learning curve only

C. Residual plot

D. Calibration histogram only

Correct Answer: A. Precision–recall curve

Introduction to Data Science
Chapter 11 of 15