Data Mining and Data Warehousing

Chapter 11
Model Evaluation, Visualization and Analytical Decision-Making

Bachelors Program in AI & ML
Data Mining and Data Warehousing   •   Bachelor

Model Evaluation, Visualization and Analytical Decision-Making

Introduction

Building a predictive or descriptive model is only part of a data-mining project. A model is useful when its performance is estimated honestly, its errors are understood, its results are communicated clearly, and its outputs support a defensible decision. Model evaluation therefore connects statistical learning with operational action.

This chapter examines evaluation strategies for classification, regression, and clustering. It also explains visualization techniques and the translation of model evidence into decisions involving costs, risks, constraints, and fairness. Particular attention is given to data leakage, class imbalance, threshold selection, and the distinction between predictive performance and business value.

Learning Objectives

After studying this chapter, a student should be able to:

1. Separate training, validation, and test data appropriately.

2. Explain and apply k-fold cross-validation.

3. Construct and interpret confusion matrices and classification metrics.

4. Calculate and interpret ROC-AUC and recognize its limitations.

5. Evaluate regression and clustering models using suitable measures.

6. Select effective visualizations for model performance and error analysis.

7. Translate analytical evidence into transparent operational decisions.

8. Identify leakage, sampling, fairness, and governance risks.

1. Evaluation as an Evidence Problem

Evaluation estimates how well a model will perform on relevant future observations. The word relevant matters: a random test sample may not represent a future population affected by time, geography, policy, or changing customer behavior.

A model-development dataset commonly has three roles:

  • Training set: used to estimate model parameters.
  • Validation set: used to select algorithms, features, hyperparameters, or decision thresholds.
  • Test set: held back until model selection is complete and used for a final estimate.

A test set must not influence feature selection, tuning, threshold choice, or repeated informal inspection. Otherwise, the reported test score becomes optimistically biased. When data are limited, cross-validation can replace a separate validation set for tuning, but a final untouched test set remains desirable.

For time-dependent data, random splitting may be inappropriate. Training should generally use earlier observations and testing later observations. For grouped data, such as several records from the same patient or customer, all records from a group should usually remain in one partition. Stratification can preserve class proportions in classification, but it does not solve temporal or group dependence.

Data leakage

Leakage occurs when information unavailable at prediction time enters the model or evaluation process. Examples include using a post-default collection code to predict default, normalizing the full dataset before splitting, or allowing duplicate customer records into both training and test sets. Leakage can produce excellent apparent performance and poor deployment performance.

A sound evaluation protocol documents the prediction time, eligible features, splitting rule, preprocessing pipeline, random seed, metric definitions, and model-selection procedure.

2. Resampling and Cross-Validation

In k-fold cross-validation, the training data are divided into k approximately equal folds. For each fold, the model is trained on the other k−1 folds and evaluated on the held-out fold. The mean score is

\[

\bar M = \frac{1}{k}\sum_{i=1}^{k}M_i,

\]

where \(M_i\) is the metric from fold i. The sample standard deviation of fold scores can describe variability, although folds are not fully independent.

Five- or ten-fold cross-validation is common. Stratified k-fold cross-validation maintains class proportions approximately in each fold. Nested cross-validation uses an inner loop for tuning and an outer loop for estimating generalization performance, reducing optimistic bias when many configurations are tried.

Cross-validation is less appropriate without modification for time series, spatial data, or clustered observations. In these cases, blocked, rolling-origin, spatial, or group cross-validation is more defensible. Resampling cannot compensate for a badly defined target or a nonrepresentative dataset.

3. Classification Evaluation

A binary classifier predicts one of two classes, such as delinquent and non-delinquent. Its predictions can be summarized by a confusion matrix:

| | Actual positive | Actual negative |

|---|---:|---:|

| Predicted positive | True positive (TP) | False positive (FP) |

| Predicted negative | False negative (FN) | True negative (TN) |

The central rates are:

\[

\text{Accuracy}=\frac{TP+TN}{TP+TN+FP+FN}

\]

\[

\text{Precision}=\frac{TP}{TP+FP},\qquad

\text{Recall}= ext{Sensitivity}=\frac{TP}{TP+FN}

\]

\[

\text{Specificity}=\frac{TN}{TN+FP},\qquad

\text{FPR}=1-\text{Specificity}=\frac{FP}{FP+TN}.

\]

Precision answers: among predicted positives, how many are positive? Recall answers: among actual positives, how many were found? These are not interchangeable. The denominators must be stated.

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

\[

F1=\frac{2PR}{P+R},

\]

provided \(P+R>0\). The harmonic mean is pulled toward the smaller value, so F1 is high only when both precision and recall are reasonably high. It ignores true negatives and does not include financial costs.

Worked example: loan-delinquency screening

The following is an illustrative, internally consistent example. A model is evaluated on 1,000 customers. The test set contains 200 actual delinquencies and 800 non-delinquencies. At a selected threshold, the model contacts 300 customers: 150 are actual delinquencies and 150 are not. The remaining 700 customers include 50 delinquencies not contacted and 650 non-delinquencies not contacted.

Thus, TP = 150, FP = 150, FN = 50, and TN = 650.

\[

\text{Accuracy}=\frac{150+650}{1000}=0.80

\]

\[

\text{Precision}=\frac{150}{150+150}=0.50

\]

\[

\text{Recall}=\frac{150}{150+50}=0.75

\]

\[

F1=\frac{2(0.50)(0.75)}{0.50+0.75}=0.60.

\]

The model identifies 75% of delinquencies, but half of the contacted customers are not delinquent. The statement that “300 contacted customers become delinquent” would be inconsistent with this test set and is not made here: the 300 contacted customers are predictions, while only 150 are true positives.

Accuracy is 80%, but it may conceal important error costs. If contacting a non-delinquent customer is expensive, precision matters. If failing to contact a delinquent customer causes substantial loss, recall matters. The appropriate threshold depends on these consequences.

Thresholds and probability quality

A classifier may output a probability rather than a class. A threshold converts probability into an action. Lowering the threshold usually increases recall and false-positive rate, while raising it usually decreases both, although empirical curves need not change smoothly.

A calibrated probability means that among cases assigned probability approximately 0.70, about 70% are positive over a sufficiently large comparable group. Discrimination and calibration differ: a model can rank cases well but produce poorly calibrated probabilities. Calibration plots, reliability diagrams, Brier score, and recalibration methods can be useful. The binary Brier score is the mean squared error of predicted probabilities:

\[

BS=\frac{1}{n}\sum_{i=1}^{n}(p_i-y_i)^2,

\]

where \(p_i\) is the predicted probability and \(y_i\in\{0,1\}\). Lower is better, though it reflects both calibration and discrimination.

ROC curve and ROC-AUC

The receiver operating characteristic (ROC) curve plots true-positive rate against false-positive rate as the classification threshold varies. The area under this curve, ROC-AUC, can be interpreted as the probability that a randomly selected positive case receives a higher score than a randomly selected negative case, subject to handling of ties.

AUC measures ranking discrimination across thresholds; it does not identify the best operating threshold and does not directly express financial value. With severe class imbalance, a high ROC-AUC may coexist with poor precision. Precision-recall curves are often more informative when positive cases are rare. Metrics should be reported with confidence intervals or repeated-sample variability when decisions are consequential.

Multiclass classification

For more than two classes, confusion matrices remain useful. Precision, recall, and F1 may be calculated per class using a one-versus-rest definition. Macro averaging gives every class equal weight; micro averaging aggregates contributions across instances; weighted averaging weights class scores by class support. The choice should reflect the application rather than be treated as a cosmetic reporting decision.

4. Regression Evaluation

Regression predicts a numerical quantity such as delivery time or energy demand. For observed values \(y_i\) and predictions \(\hat y_i\), residuals are \(e_i=y_i-\hat y_i\).

Mean absolute error is

\[

MAE=\frac{1}{n}\sum_{i=1}^{n}|y_i-\hat y_i|.

\]

It is expressed in the target’s units and is relatively interpretable. Mean squared error is

\[

MSE=\frac{1}{n}\sum_{i=1}^{n}(y_i-\hat y_i)^2,

\]

and root mean squared error is \(RMSE=\sqrt{MSE}\). Squared-error measures penalize large errors more strongly than MAE.

The coefficient of determination is

\[

R^2=1-\frac{\sum_i(y_i-\hat y_i)^2}{\sum_i(y_i-\bar y)^2},

\]

where \(\bar y\) is the mean of observed target values in the evaluation sample. Relative to the mean baseline, positive values indicate improvement; R² can be negative on test data. It is not a percentage of predictions that are correct, and a high R² does not guarantee low operational error.

For positive targets, percentage metrics can be useful but require care near zero. MAPE is undefined when an actual value is zero and can heavily weight small actual values. Alternatives include symmetric or weighted measures, log-scale evaluation, or a domain-specific cost function. Always report units and compare against a simple baseline such as the training mean or a seasonal naive forecast.

Residual plots against fitted values, time, important features, and groups can reveal nonlinearity, heteroscedasticity, drift, and systematic underprediction. Prediction intervals, when available, communicate uncertainty better than point predictions alone.

5. Clustering Evaluation

Clustering has no single universally correct metric because “good” clusters may mean compact, separated, stable, interpretable, or operationally useful groups.

The within-cluster sum of squares (WCSS), often used in k-means, is

\[

WCSS=\sum_{j=1}^{k}\sum_{x_i\in C_j}\|x_i-\mu_j\|^2,

\]

where \(C_j\) is cluster j and \(\mu_j\) its centroid. WCSS never increases when k increases, so the elbow method is heuristic rather than a proof of the correct number of clusters.

The silhouette coefficient for observation i compares its average distance to its own cluster, \(a(i)\), with the smallest average distance to another cluster, \(b(i)\):

\[

s(i)=\frac{b(i)-a(i)}{\max\{a(i),b(i)\}}.

\]

For ordinary distance settings with at least two clusters, values near 1 indicate separation, values near 0 indicate overlap, and negative values suggest possible assignment to the wrong cluster. Scaling, distance choice, outliers, and cluster shape strongly affect results.

When trusted labels exist, external measures such as adjusted Rand index or normalized mutual information may be used, but clustering can be valuable even without labels. Stability under resampling, domain interpretation, and usefulness in a downstream task should accompany internal scores.

6. Visualization for Diagnosis and Communication

A visualization should answer a question, not merely decorate a report.

Useful plots include:

  • Confusion matrices, preferably with counts and row or column percentages.
  • ROC and precision-recall curves for threshold comparison.
  • Calibration plots for probability reliability.
  • Lift and gain charts for ranked targeting.
  • Residual-versus-fitted and residual-versus-time plots for regression diagnosis.
  • Error distributions and subgroup error plots.
  • Learning curves showing performance as training size increases.
  • Feature-importance or model-explanation plots, accompanied by a warning that association is not causation.
  • Cluster scatterplots after dimensionality reduction, clearly labeling the projection and its limitations.

Use consistent class labels, informative axes, units, denominators, sample sizes, and uncertainty where appropriate. Avoid truncated axes when they exaggerate differences, overloaded color schemes, and three-dimensional plots that hinder comparison. Accessibility requires sufficient contrast, patterns or labels in addition to color, and readable typography.

7. From Metrics to Analytical Decisions

A metric becomes decision evidence only after connecting it to an action. A useful decision workflow is:

1. Define the decision, affected population, prediction time, and harm of errors.

2. Establish a simple baseline and operational constraints.

3. Select metrics aligned with the decision, not merely those supplied by software.

4. Compare thresholds or policies using validation data.

5. Estimate uncertainty and test subgroup and temporal robustness.

6. Assess costs, benefits, capacity, and legal or ethical constraints.

7. Confirm performance on the untouched test set.

8. Monitor post-deployment drift, outcomes, and unintended effects.

Suppose a binary action has benefit \(B\) for each true positive, cost \(C_{FP}\) for each false positive, and cost \(C_{FN}\) for each false negative. A simplified expected net value is

\[

V=B(TP)-C_{FP}(FP)-C_{FN}(FN)-C_A N_A,

\]

where \(C_A N_A\) represents other action costs, such as contacting selected customers. This expression is a decision model, not a universal metric: costs must be justified, time horizons specified, and downstream effects considered.

Threshold optimization on the test set is invalid because it uses test outcomes to select the policy. Thresholds should be selected using training/validation procedures, then evaluated once on the test set. If the model’s output is used to allocate scarce resources, capacity constraints should be included in evaluation.

Model performance should also be examined across relevant groups. Differences may arise from data quality, prevalence, measurement processes, or unequal consequences. Fairness analysis must specify the protected or relevant groups, metric, legal context, and trade-offs; no single fairness metric resolves every policy question. Human review does not automatically eliminate bias, and automated decisions may require explanation, contestability, documentation, and auditability.

8. Illustrative Integrated Case: Delinquency Outreach

Background and problem

A financial institution wants to prioritize outreach to customers at risk of loan delinquency. It has historical customer records and defines the target as delinquency within the next 60 days. Outreach capacity is limited to 300 of 1,000 customers per campaign.

Analysis and approach

The institution performs a time-based split: earlier campaigns are used for training and validation, while a later campaign is held out for testing. Features are restricted to information available before the prediction date. A probability model is tuned using stratified procedures within the development period. The threshold is chosen to produce approximately 300 contacts while considering contact cost and the harm of missed delinquency.

On the untouched test campaign, there are 200 actual delinquencies and 800 non-delinquencies. The policy contacts 300 customers. Of those contacted, 150 are delinquent and 150 are not. Among the 700 not contacted, 50 are delinquent and 650 are not. Consequently, recall is 0.75, precision is 0.50, specificity is 650/800 = 0.8125, and accuracy is 0.80.

Decision interpretation

The institution should not conclude simply that the model is “80% accurate.” It should ask whether contacting 150 true delinquencies creates enough benefit to justify contacting 150 non-delinquencies and missing 50 delinquencies. It should compare this policy with contacting customers at random, a rules-based policy, and contacting the highest-risk customers without a model. Calibration and lift charts can show whether the ranking supports capacity-limited outreach.

Outcome and governance

Before deployment, the institution should test performance across relevant customer groups, verify that features are lawful and appropriate, provide a process for review or appeal where required, and monitor changes in delinquency rates and contact outcomes. The model should be retrained or recalibrated only through a documented change process. The case demonstrates that a confusion matrix is a starting point for a decision, not the decision itself.

9. Limitations and Contemporary Practice

Evaluation estimates performance under specified conditions; it does not guarantee future success. Distribution shift, concept drift, feedback loops, selective labels, missing outcomes, and changing policies can invalidate historical estimates. Post-deployment monitoring should track data quality, prediction distributions, calibration, subgroup performance, alert rates, and realized outcomes.

Modern machine-learning systems may produce many candidate models, increasing the risk of selection bias and repeated experimentation on the test set. Versioned datasets, reproducible pipelines, model cards, data documentation, independent review, and pre-specified evaluation plans improve credibility. Explainable-AI tools can support diagnosis and communication, but feature-attribution explanations are not necessarily causal explanations.

Best-Practice Checklist

  • Define the target and prediction time precisely.
  • Split data according to time, groups, or sampling design.
  • Fit preprocessing only on training folds.
  • Keep the final test set untouched until the end.
  • Report counts as well as rates.
  • Use metrics aligned with error costs and class prevalence.
  • Compare with meaningful baselines.
  • Inspect calibration, subgroups, and temporal stability.
  • Visualize errors, not only average scores.
  • Document thresholds, uncertainty, limitations, and governance controls.

Chapter Summary

Reliable model evaluation requires separation of training, validation, and test information, with cross-validation adapted to the data-generating structure. Confusion matrices support precise interpretation of accuracy, precision, recall, specificity, and F1, while ROC-AUC evaluates ranking across thresholds rather than selecting an operating policy. Regression requires measures such as MAE, RMSE, and R² interpreted with units and baselines. Clustering evaluation combines compactness, separation, stability, and domain usefulness. Visualizations reveal threshold behavior, calibration, residual structure, subgroup differences, and cluster quality. Finally, analytical decisions must connect metrics to costs, capacity, uncertainty, fairness, governance, and monitoring. A defensible model is therefore not merely accurate; it is evaluated honestly and used responsibly.

Key Terms

Data leakage: Use of information unavailable at prediction time.

Training set: Data used to estimate model parameters.

Validation set: Data used to tune models or policies.

Test set: Held-out data used for final performance estimation.

Cross-validation: Repeated training and validation across data folds.

Confusion matrix: Table of observed and predicted classification outcomes.

True positive: A correctly predicted positive case.

Precision: Proportion of predicted positives that are actually positive.

Recall: Proportion of actual positives that are identified.

Specificity: Proportion of actual negatives correctly rejected.

F1 score: Harmonic mean of precision and recall.

ROC curve: Plot of true-positive rate against false-positive rate across thresholds.

ROC-AUC: Area under the ROC curve, measuring ranking discrimination.

Calibration: Agreement between predicted probabilities and observed frequencies.

MAE: Mean absolute error for regression predictions.

RMSE: Square root of mean squared error.

Silhouette coefficient: Cluster-quality measure based on within- and between-cluster distances.

Concept drift: Change over time in the relationship between inputs and the target.

Decision threshold: Rule converting a score or probability into an action.

Fairness audit: Structured examination of performance and impacts across groups.

Review Questions

Short Answer Questions

1. What is the principal purpose of an untouched test set?

2. Distinguish precision from recall.

3. Why can accuracy be misleading for imbalanced classes?

4. What does MAE measure, and in what units is it expressed?

5. Why does WCSS alone not determine the correct number of clusters?

Long Answer Questions

1. Explain a complete train-validation-test workflow, including leakage prevention and the role of cross-validation.

2. Compare ROC-AUC, precision-recall curves, calibration, and F1 for a rare-event classification problem.

3. Discuss MAE, RMSE, R², and residual analysis as tools for regression evaluation.

4. Explain how threshold selection should incorporate costs, capacity, uncertainty, and fairness.

5. Describe how visual analytics and post-deployment monitoring contribute to trustworthy model use.

Analytical / Application Questions

1. In a test set of 2,000 cases, TP = 180, FP = 120, FN = 60, and TN = 1,640. Calculate accuracy, precision, recall, specificity, and F1.

2. A bank can contact only 10% of customers. Design an evaluation plan comparing a risk model with random selection and an existing rules-based policy. Specify metrics, data split, and decision evidence.

3. A regression model has low overall MAE but substantially larger errors for rural customers and during holiday periods. Propose diagnostic visualizations, possible causes, and a defensible deployment response.

Multiple Choice Questions with Answers

Question 1

Which dataset should remain untouched until model selection and threshold tuning are complete?

A. Training set

B. Validation set

C. Test set

D. Resampling set

Correct Answer: C. Test set

Question 2

In the loan example, what is the precision when TP = 150 and FP = 150?

A. 0.25

B. 0.50

C. 0.75

D. 0.80

Correct Answer: B. 0.50

Question 3

Which metric is the harmonic mean of precision and recall?

A. Accuracy

B. Specificity

C. F1 score

D. ROC-AUC

Correct Answer: C. F1 score

Question 4

What does ROC-AUC primarily measure?

A. Probability calibration at one threshold

B. Ranking discrimination across thresholds

C. The number of false negatives at a fixed threshold

D. The average monetary value of a policy

Correct Answer: B. Ranking discrimination across thresholds

Question 5

Which regression metric is expressed in the original target units and uses absolute errors?

A. MAE

B. MSE

C. R²

D. ROC-AUC

Correct Answer: A. MAE

Question 6

If a model has TP = 80 and FN = 20, what is its recall?

A. 0.20

B. 0.50

C. 0.80

D. 0. ma

Correct Answer: C. 0.80

Question 7

Why is WCSS alone insufficient for choosing the number of clusters?

A. It always increases as clusters increase

B. It always decreases as clusters increase

C. It cannot be calculated for k-means

D. It measures classification accuracy

Correct Answer: B. It always decreases as clusters increase

Question 8

Which practice best prevents leakage during preprocessing?

A. Fit preprocessing on the complete dataset before splitting

B. Fit preprocessing separately using information from each training fold only

C. Use the test labels to select features

D. Duplicate rare cases into every fold

Correct Answer: B. Fit preprocessing separately using information from each training fold only

Question 9

A calibration plot primarily compares predicted probabilities with:

A. Observed event frequencies

B. The number of model features

C. Training time

D. Cluster centroids

Correct Answer: A. Observed event frequencies

Question 10

For time-dependent data, which split is generally most defensible?

A. Randomly mix all dates into every partition

B. Train on later observations and test on earlier observations

C. Train on earlier observations and test on later observations

D. Use only the highest-valued observations for testing

Correct Answer: C. Train on earlier observations and test on later observations

Data Mining and Data Warehousing
Chapter 11 of 15