Supervised & Unsupervised Learning

Chapter 8
Model Evaluation, Selection and Tuning

Graduate Program in Business Analytics
Supervised & Unsupervised Learning   •   Graduate

Model Evaluation, Selection and Tuning

Introduction

A predictive model is useful only when its performance is evaluated against future data and judged in relation to the decision it supports. A model with excellent training accuracy may fail in production because it has memorized noise, because the validation design was inappropriate, or because the evaluation metric did not represent the organization’s economic objective. Model evaluation therefore concerns more than calculating a score. It involves defining the prediction task, constructing a credible estimate of generalization performance, selecting an appropriate metric, tuning model complexity, quantifying uncertainty, and translating predictive performance into business value.

This chapter develops a framework for regression, classification, ranking, and probability calibration. It also explains holdout validation, cross-validation, nested validation, bootstrap resampling, statistical comparison, hyperparameter optimization, and decision-oriented model selection.

Learning Objectives

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

  1. Distinguish training, validation, and test data and design appropriate data-splitting procedures.
  2. Explain the logic, assumptions, strengths, and limitations of cross-validation and nested validation.
  3. Select and interpret metrics for regression, classification, ranking, and calibration.
  4. Tune hyperparameters without contaminating performance estimates.
  5. Compare models statistically and communicate uncertainty.
  6. Align model choice with costs, benefits, constraints, and organizational risk.
  7. Identify leakage, sampling bias, temporal dependence, and other threats to valid evaluation.

1. Generalization and the Evaluation Problem

Let a dataset consist of observations (xi,yi), where xi is a vector of predictors and yi is the observed outcome. A learning algorithm uses training data Dtrain to produce a fitted model fhat. The central quantity of interest is expected predictive loss on future observations:

R(f̂) = E[L(Y, f̂(X))]

Here, L is a loss function, X and Y are future predictor and outcome variables, and the expectation is taken over the population generating future cases. Because the population distribution is unknown, R(fhat) must be estimated using observed data.

Training error is usually optimistic because the model was constructed to fit the training observations. A flexible model can reduce training error while increasing future error. This is the practical expression of the bias–variance trade-off: simpler models may have higher systematic error but lower sensitivity to sampling variation, whereas highly flexible models may fit the training sample closely but vary substantially across samples.

A valid evaluation procedure must address three questions:

  • What is the target population? For example, future customers, hospitals in a new region, or transactions next month.
  • What information is available at prediction time? Variables created after the outcome occurs must not be used.
  • What loss matters? A missed fraud case, a false medical alarm, and a small demand forecast error do not have equivalent consequences.

2. Holdout Validation and Data Splitting

The simplest design divides data into training and test sets. The model is fitted on training data and evaluated once on the untouched test set. When model choices and hyperparameters are selected using a validation set, a three-way split is used:

PartitionPrimary purposeUsed for fitting parameters?Used for final reporting?
TrainingEstimate model parametersYesNo
ValidationSelect algorithms and hyperparametersIndirectlyNo
TestEstimate final generalization performanceNoYes

A test set should be opened only after all material decisions have been finalized. Repeatedly inspecting test performance turns the test set into another validation set and produces optimistic estimates.

For independent and identically distributed observations, random splitting may be reasonable. Stratification is useful for classification when the positive class is rare: each partition is constructed to preserve approximately the overall class proportions. However, stratification does not solve dependence problems. Observations from the same customer, patient, household, or account should often be grouped so that related records do not appear in both training and test data.

Time-dependent data require temporal splitting. A model trained on January–September data may be evaluated on October data. Random splitting could allow information from the future to influence the past and would generally overstate performance.

A test-set estimate of mean loss is

L̄test = (1/ntest) ∑i∈test L(yi, f̂(xi))

where ntest is the number of test observations. This estimate is appropriate when the test observations represent the intended future population and are not used in model development.

3. Cross-Validation

Cross-validation uses repeated training and validation subsets to make more efficient use of limited data. In K-fold cross-validation, the data are partitioned into K approximately equal folds. For fold k, the model is trained on all observations outside that fold and evaluated on the held-out fold. The cross-validated loss is

CVK = (1/K) ∑k=1K (1/|Vk|) ∑i∈Vk L(yi, f̂^(−k)(xi))

Here, Vk is validation fold k, |Vk| is its size, and fhat^(−k) is trained without fold k. The formula assumes folds are formed in a manner consistent with the data-generating process.

Common choices are five- or ten-fold cross-validation. Leave-one-out cross-validation uses K=n, where each observation is held out once. It uses nearly all observations for training but can have high variance and substantial computational cost. Ten-fold cross-validation often offers a practical balance.

Cross-validation must include every operation that learns from data inside each training fold. For example, standardization, imputation, feature selection, target encoding, and resampling must be fitted within the fold. A pipeline prevents leakage:

  1. Split the data into training and validation folds.
  2. Fit preprocessing only on the training portion.
  3. Transform the validation portion using the fitted preprocessing.
  4. Fit the model on transformed training data.
  5. Evaluate on transformed validation data.

If preprocessing is performed before cross-validation, information from validation folds may influence the model and bias the score.

Variants for structured data

  • Stratified cross-validation: preserves class proportions.
  • Group cross-validation: keeps all observations from a group in the same fold.
  • Rolling or expanding-window validation: respects temporal order.
  • Blocked spatial validation: prevents nearby observations from being split across folds when spatial dependence is important.
  • Repeated cross-validation: repeats fold construction to assess sensitivity to partitioning.

Cross-validation estimates performance for the modeling process, not merely for a single fitted parameter vector. Its uncertainty depends on sample size, fold construction, outcome noise, and dependence among fold estimates.

4. Nested Validation and Hyperparameter Tuning

Hyperparameters control the learning procedure rather than being estimated directly as ordinary model coefficients. Examples include tree depth, regularization strength, number of neighbors, learning rate, and the number of boosting iterations.

If hyperparameters are selected by minimizing cross-validation error and the same score is reported as unbiased performance, the estimate is optimistic because the selection process has adapted to random validation variation. Nested cross-validation separates tuning from evaluation.

In an outer loop, data are divided into outer training and outer test folds. Within each outer training fold, an inner cross-validation procedure selects hyperparameters. The selected model is then refitted on the complete outer training fold and evaluated once on the outer test fold. The final estimate averages outer-fold performance.

CVnested = (1/Kouter) ∑j=1Kouter Lossj(θ̂j)

thetahatj denotes the hyperparameters selected using only the inner folds of outer training set j, and Lossj is the loss on the untouched outer test fold.

Nested validation is especially important when the dataset is small, many algorithms are compared, or a large hyperparameter space is searched. It is computationally expensive, so a separate final test set may be unnecessary when nested cross-validation has been designed and reported correctly. In high-stakes applications, an additional temporal or external test set is often desirable.

5. Metrics for Regression

A metric should reflect the decision problem and the scale on which errors matter.

Mean absolute error

MAE = (1/n) ∑i=1n |yi − ŷi|

MAE is in the same units as the outcome and gives equal linear weight to absolute errors. It is relatively robust to outliers compared with squared-error metrics.

Mean squared error and root mean squared error

MSE = (1/n) ∑i=1n (yi − ŷi)2
RMSE = √MSE

RMSE is also in outcome units, but large errors receive disproportionately high weight. It is appropriate when large mistakes are especially costly or when squared-error estimation is substantively justified.

Mean absolute percentage error

MAPE = (100%/n) ∑i=1n |(yi − ŷi)/yi|

MAPE is undefined when yi=0 and unstable when actual values are close to zero. It can also penalize proportional errors asymmetrically. Alternatives include weighted absolute percentage error, symmetric percentage measures, or a log-scale loss, depending on the application.

Coefficient of determination

R² = 1 − [∑(yi − ŷi)² / ∑(yi − ȳ)²]

The denominator is the total squared deviation from the sample mean ybar. On test data, R² may be negative if the model performs worse than the mean baseline. R² is not a universal measure of predictive usefulness and should not replace error measures.

6. Metrics for Classification

For binary classification, let the positive class be the event of interest. A confusion matrix contains true positives, false positives, true negatives, and false negatives.

Actual positiveActual negative
Predicted positiveTPFP
Predicted negativeFNTN

Accuracy is

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

It can be misleading under class imbalance. Precision and recall are

Precision = TP/(TP + FP)
Recall = TP/(TP + FN)

Precision answers, “Among predicted positives, how many are positive?” Recall answers, “Among actual positives, how many are detected?” Specificity is TN/(TN+FP).

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

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

It is useful when both precision and recall matter, but it ignores true negatives and does not directly encode financial costs.

Threshold-independent measures include the area under the receiver operating characteristic curve (ROC AUC), which measures ranking discrimination across thresholds, and precision–recall AUC, which is often more informative when the positive class is rare. AUC should not be interpreted as the probability that a model is correct for every case; it summarizes pairwise ranking performance.

For cost-sensitive decisions, expected cost can be written as

Expected cost = cFP × FP + cFN × FN + caction × Naction

where cFP, cFN, and caction are relevant unit costs and Naction is the number of other actions. The threshold should be selected using costs, benefits, capacity, and constraints rather than automatically using 0.5.

7. Ranking and Recommendation Metrics

Ranking models order cases rather than merely assigning labels. This is central to search, credit investigation, lead prioritization, and recommender systems.

  • Precision@k: proportion of the top k ranked items that are relevant.
  • Recall@k: proportion of all relevant items appearing in the top k.
  • Discounted cumulative gain (DCG): gives greater weight to relevant items appearing near the top. A common form is
DCG@k = ∑r=1k (2relr − 1)/log₂(r + 1)

where relr is the relevance grade at rank r. Normalized DCG divides DCG by the ideal DCG for that query, producing a value commonly between zero and one.

  • Mean reciprocal rank: the reciprocal of the rank of the first relevant item, averaged across queries.
  • Lift: response rate in a selected ranked segment divided by the overall response rate.

Ranking evaluation must respect the unit of analysis. If several records belong to one customer or query, metrics should be computed at the appropriate customer or query level. Offline ranking metrics may not predict online value if users change behavior in response to recommendations.

8. Calibration and Probabilistic Predictions

Discrimination concerns ordering: whether high-risk cases tend to rank above low-risk cases. Calibration concerns probability accuracy. A model is calibrated if among cases assigned probability p, approximately a fraction p experience the event.

A calibration plot groups predictions into bins and compares mean predicted probability with observed event frequency. The Brier score for binary outcomes is

Brier = (1/n) ∑i=1n (p̂i − yi)2

where yi is zero or one and phati is the predicted probability. Lower values are better. The Brier score reflects both calibration and discrimination, so it should not be interpreted as a pure calibration measure.

Calibration methods include Platt scaling, which fits a logistic transformation to model scores, and isotonic regression, a flexible monotonic calibration method. Calibration must be learned using data separate from the data used to fit the original model, or through nested cross-validation. A calibrated model may be more valuable than a slightly more discriminative model when decisions depend on expected probabilities, such as pricing, capacity planning, or treatment selection.

9. Hyperparameter Search and Model Selection

A disciplined tuning process begins with a baseline. Baselines include the mean for regression, the majority class for classification, a seasonal naïve forecast, or a simple business rule. A complex model is useful only if it improves on a credible baseline under realistic evaluation.

Search strategies include:

  • Grid search: evaluates a predefined Cartesian grid; transparent but inefficient in high dimensions.
  • Random search: samples configurations and often explores important dimensions more efficiently.
  • Bayesian optimization: uses previous evaluations to select promising configurations; useful when evaluations are expensive.
  • Successive halving or early stopping: allocates more resources to promising configurations.

Search spaces should reflect domain knowledge. Regularization parameters are often searched on a logarithmic scale because useful values may span several orders of magnitude. Hyperparameter selection should consider computational cost, latency, memory, interpretability, and stability, not only a small improvement in a metric.

The “one-standard-error” principle selects the simplest model whose estimated performance is within one standard error of the best model. This can improve robustness and maintainability, although the standard error must be estimated appropriately and the principle is not a substitute for business judgment.

10. Statistical Comparison of Models

A difference in validation scores is not automatically meaningful. For paired predictions, calculate the observation-level loss difference:

di = L(yi, fA(xi)) − L(yi, fB(xi))

The mean difference is dbar = (1/n) sum di. A positive value indicates that model B has lower loss under this definition. Because predictions are paired on the same observations, paired methods are generally more efficient than comparing unrelated samples.

Uncertainty may be assessed using repeated cross-validation, bootstrap resampling, or confidence intervals for paired loss differences. However, cross-validation fold scores are correlated because training sets overlap. Naïvely treating folds as independent can produce overly narrow intervals. For time series and grouped data, resampling must preserve dependence, for example through block or cluster bootstrap procedures.

Statistical significance is not the same as practical significance. A tiny improvement can be statistically detectable in a very large sample but economically irrelevant. Conversely, a meaningful improvement may be uncertain in a small sample. Model comparisons should report point estimates, uncertainty intervals, sample size, data regime, metric definitions, and the number of model searches performed.

11. Aligning Performance with Economic Outcomes

Technical metrics are proxies for organizational value. Suppose a fraud model assigns a probability of fraud p. Investigating a transaction costs cI, approving a fraudulent transaction costs cF, and declining a legitimate transaction incurs opportunity cost cL. An action should be chosen by comparing expected consequences, not by maximizing AUC alone.

Expected utility for an investigation might be represented as:

EU(investigate) = p × benefitofpreventingfraud − cI

The calculation is valid only when the probability is reasonably calibrated and the benefits and costs are defined consistently. Real decisions may also involve investigation capacity, regulatory constraints, customer fairness, and delayed outcomes.

A model with lower RMSE may be inferior if it is expensive to operate, difficult to explain, unstable across regions, or systematically inaccurate for a protected group. Model selection is therefore a constrained optimization problem involving predictive quality, cost, risk, fairness, interpretability, latency, and resilience.

12. Illustrative Case: Subscription Churn Intervention

Background

A telecommunications firm wants to identify customers likely to cancel within 30 days. The retention team can contact only 10% of customers each week. An illustrative dataset contains 50,000 customer-month observations, with a 6% cancellation rate.

Problem

The analytics team compares logistic regression, random forest, and gradient boosting. An initial random split creates leakage because a customer’s later service status appears in the training data while an earlier record for the same customer appears in the test data.

Analysis and approach

The team first defines the prediction timestamp and excludes variables unavailable at that time. It then uses a customer-level grouped split and a temporal test period. Within training data, missing-value imputation, scaling, and feature selection are fitted inside each cross-validation fold. Hyperparameters are selected through five-fold inner cross-validation, while four outer folds estimate performance.

Because the retention team has limited capacity, the principal metric is recall among the top 10% of ranked customers, supplemented by precision@10%, calibration, and expected net value. The model probabilities are calibrated using a separate calibration procedure. A simple logistic model is retained as a benchmark.

Suppose the gradient-boosting model achieves higher ROC AUC but lower precision@10% than the logistic model. The logistic model also has better calibration and is easier to explain to customer-service managers. If the top-decile intervention produces greater expected net value, the logistic model is preferable even though its AUC is lower.

Outcome and learning points

The firm deploys the logistic model with a threshold determined by weekly capacity rather than a default probability threshold. Monitoring tracks calibration, top-decile lift, subgroup performance, data drift, intervention effects, and realized retention profit. The case demonstrates that the best model is defined by the complete decision system, not by a single leaderboard metric.

13. Challenges, Governance, and Contemporary Practice

Evaluation can fail through target leakage, selective labels, nonrepresentative samples, outcome delay, concept drift, and feedback loops. In credit, for example, outcomes are observed only for applicants who receive loans; rejected applicants do not provide straightforward counterfactual labels. In recommendation systems, exposure affects clicks, so logged data may reflect previous ranking policies rather than user preferences independent of those policies.

Fairness evaluation should examine error rates, calibration, selection rates, and subgroup-specific consequences where legally and substantively appropriate. Some fairness criteria cannot generally be satisfied simultaneously when base rates differ, so organizations must document the chosen objective and its justification. Sensitive attributes may be needed for auditing even when excluded from prediction.

Governance practices include versioning data and code, documenting evaluation populations, preserving untouched test data, recording search spaces, publishing confidence intervals, monitoring drift, and establishing rollback criteria. Post-deployment evaluation should distinguish predictive performance from causal impact: a churn model may predict who will leave without identifying who can be successfully retained by an intervention.

Modern automated machine-learning systems can search algorithms and hyperparameters rapidly, but automation does not remove the need for valid splits, appropriate metrics, leakage controls, or economic reasoning. Reproducibility, external validation, and human review remain essential.

Best-Practice Checklist

  1. Define the prediction time, target population, outcome window, and decision.
  2. Choose splits that respect time, groups, geography, and dependence.
  3. Establish simple and operationally meaningful baselines.
  4. Fit all data-dependent preprocessing within training folds.
  5. Use nested validation when tuning and reporting performance on the same dataset.
  6. Select metrics that match error costs and capacity constraints.
  7. Evaluate both discrimination and calibration when probabilities support decisions.
  8. Report uncertainty and practical effect sizes, not only point estimates.
  9. Examine subgroup performance, leakage, drift, and robustness.
  10. Refit only after the evaluation design is complete, and preserve an honest final test or external validation set.

Chapter Summary

Model evaluation estimates how a learning process will perform on future data. Holdout designs are simple but can be inefficient; cross-validation uses data more efficiently, while nested validation separates hyperparameter selection from unbiased performance estimation. Splits must reflect time, groups, geography, and other dependencies, and every learned preprocessing step must occur inside the relevant training fold.

Regression evaluation commonly uses MAE, RMSE, MAPE with caution, and R². Classification evaluation uses confusion-matrix measures, threshold-independent ranking metrics, and cost-sensitive decision analysis. Ranking tasks require metrics such as precision@k, recall@k, and nDCG. Calibration evaluates whether predicted probabilities correspond to observed frequencies and is essential when decisions depend on expected risk.

Hyperparameter search should be controlled, reproducible, and evaluated without leakage. Statistical comparison requires paired predictions and uncertainty analysis, while practical model selection must incorporate economic value, capacity, interpretability, fairness, latency, and governance. The technically strongest model is not always the best organizational model.

Key Terms

Generalization error: Expected loss on future observations from the target population.

Training set: Data used to estimate model parameters.

Validation set: Data used to select models, features, or hyperparameters.

Test set: Untouched data used for final performance estimation.

Data leakage: Use of information during development that would not be available at prediction time.

Cross-validation: Repeated training and validation across partitions of a dataset.

Nested cross-validation: An outer evaluation loop containing an inner tuning loop.

Hyperparameter: A setting controlling the learning procedure rather than an ordinary fitted coefficient.

MAE: Mean absolute error, the average absolute prediction error.

RMSE: Root mean squared error, emphasizing large errors.

Precision: Fraction of predicted positives that are truly positive.

Recall: Fraction of actual positives that are detected.

ROC AUC: Area under the receiver operating characteristic curve.

Calibration: Agreement between predicted probabilities and observed frequencies.

Brier score: Mean squared error of binary probability predictions.

Ranking metric: A measure evaluating the order in which cases or items are presented.

Bootstrap: Resampling procedure used to estimate sampling variability.

Concept drift: Change in the relationship between predictors and outcomes over time.

Expected utility: Value of an action after accounting for probabilities, benefits, and costs.

Model governance: Processes controlling documentation, validation, monitoring, and responsible use.

Review Questions

Short Answer Questions

  1. Why is training error generally an optimistic estimate of future predictive error?
  2. What is the principal distinction between a validation set and a test set?
  3. When is grouped cross-validation preferable to ordinary random cross-validation?
  4. What is the difference between discrimination and calibration?
  5. Why can accuracy be misleading for a highly imbalanced classification problem?

Long Answer Questions

  1. Explain how to design a nested cross-validation procedure for selecting and evaluating a machine-learning model.
  2. Compare MAE, RMSE, MAPE, and R², including their assumptions and limitations.
  3. Discuss how threshold selection should incorporate costs, benefits, class prevalence, and operational capacity.
  4. Explain why preprocessing must be performed inside cross-validation folds and provide examples of leakage.
  5. Discuss the technical, economic, ethical, and governance factors that should influence model selection.

Analytical / Application Questions

  1. A fraud model has 99% accuracy but detects only 20% of fraudulent transactions. Explain why this may occur and propose a more suitable evaluation framework.
  2. A retailer can contact only the top 5% of customers ranked by churn risk. Which metrics would you report, and how would you test whether the model creates economic value?
  3. A forecasting dataset contains five years of monthly observations and strong seasonality. Design a validation strategy and justify why an ordinary random split may produce misleading results.

Multiple Choice Questions with Answers

Question 1

Which procedure provides the most reliable estimate when hyperparameters are tuned and performance is evaluated using the same dataset?

A. Training error evaluation

B. Nested cross-validation

C. A single random training split without validation

D. Evaluation on the majority-class baseline

Correct Answer: B. Nested cross-validation

Question 2

Which metric is expressed in the same units as the regression outcome and gives linear weight to absolute errors?

A. MAE

B. MSE

C. R²

D. MAPE

Correct Answer: A. MAE

Question 3

A classifier predicts 80 positive cases, of which 60 are truly positive. What is its precision?

A. 20%

B. 60%

C. 75%

D. 80%

Correct Answer: C. 75%

Question 4

Which validation design is most appropriate when observations from the same customer are correlated?

A. Random observation-level splitting

B. Group cross-validation

C. Leave-one-feature-out validation

D. Majority-class validation

Correct Answer: B. Group cross-validation

Question 5

What does calibration assess?

A. Whether predictors are normally distributed

B. Whether high-probability predictions rank above low-probability predictions only

C. Whether predicted probabilities correspond to observed event frequencies

D. Whether the model has zero training error

Correct Answer: C. Whether predicted probabilities correspond to observed event frequencies

Question 6

Which metric is especially designed to evaluate the quality of the top portion of a ranked list?

A. Precision@k

B. MSE

C. Specificity at every threshold averaged without ranking

D. Training accuracy

Correct Answer: A. Precision@k

Question 7

If false negatives are much more costly than false positives, which action is generally appropriate?

A. Choose a threshold without considering costs

B. Always optimize accuracy

C. Consider a lower threshold, subject to capacity and other constraints

D. Remove the positive class from evaluation

Correct Answer: C. Consider a lower threshold, subject to capacity and other constraints

Question 8

Why should imputation be fitted separately within each cross-validation training fold?

A. To increase the number of variables

B. To prevent validation information from leaking into model development

C. To guarantee a higher AUC

D. To eliminate class imbalance

Correct Answer: B. To prevent validation information from leaking into model development

Question 9

A model has lower RMSE but substantially higher operating cost and poorer calibration than a simpler alternative. What is the best conclusion?

A. The lower-RMSE model must always be deployed

B. The simpler model may be preferable after considering the complete decision objective

C. Calibration is irrelevant whenever RMSE is reported

D. Operating cost cannot be part of model selection

Correct Answer: B. The simpler model may be preferable after considering the complete decision objective

Question 10

Why can a random split be inappropriate for forecasting future demand?

A. It always reduces sample size to one observation

B. It may allow information from future periods to influence evaluation of earlier periods

C. It prevents calculation of MAE

D. It guarantees underfitting

Correct Answer: B. It may allow information from future periods to influence evaluation of earlier periods

Supervised & Unsupervised Learning
Chapter 8 of 15