Classification and Prediction · Data Mining

Evaluating the Accuracy of a Classifier or Predictor

Watch lectures

Evaluating the Accuracy of a Classifier or Predictor

1. Why Not Simply Use Training Accuracy?

The resubstitution (training-set) accuracy is optimistically biased: a model can memorise (overfit) the training data and still generalise poorly — the classic example is a 1-NN classifier, which has 0% training error but a large test error. Hence, evaluation must use data not seen during training.

Holdout method: split the data into two independent sets — a training set (typically 2/3) and a test set (1/3). Accuracy is measured on the test set.

 Full dataset (n tuples)
 +--------------------------+-----------------+
 |      TRAINING (2/3)      |   TEST (1/3)    |
 +--------------------------+-----------------+
          build model          measure accuracy

Problem — the estimate depends on the split. The same accuracy figure can vary with different partitions of the data, so confidence intervals or resampling methods are needed.

2. Random Sampling (Repeated Holdout)

Repeat the holdout kk times with random, stratified partitions (stratified = class proportions preserved in each set) and average:

acc=1k∑i=1kacci,σ=1k−1∑i=1k(acci−acc‾)2\text{acc} = \frac{1}{k}\sum_{i=1}^{k}\text{acc}_i,\qquad \sigma = \sqrt{\frac{1}{k-1}\sum_{i=1}^{k}(\text{acc}_i-\overline{\text{acc}})^{2}}

Some tuples are never used for testing, while others are tested repeatedly; still, this is the simplest unbiased-in-expectation estimator.

3. Cross-Validation (kk-fold CV)

Algorithm

  1. Randomly partition the data into kk mutually exclusive subsets ("folds") D1,…,DkD_1, \dots, D_k, each of roughly equal size (stratified).
  2. For each fold ii: train on all folds except DiD_i, test on DiD_i to get acci\text{acc}_i.
  3. Overall accuracy = average of the kk accuracies; every tuple is used for testing exactly once and for training k−1k-1 times.
accCV=1k∑i=1kacci,errorCV=1k∑i=1k(1−correcti∣Di∣)\text{acc}_{CV}=\frac{1}{k}\sum_{i=1}^{k}\text{acc}_i,\qquad \text{error}_{CV}=\frac{1}{k}\sum_{i=1}^{k}\Big(1-\frac{\text{correct}_i}{|D_i|}\Big)

Choice of kk

kk Training size per fold Notes
2 50% Weak, high bias
5 80% Good compromise
10 90% Standard practice — lowest bias/variance trade-off, reasonable computation
nn (Leave-One-Out, LOO) n−1n-1 (almost all) Nearly unbiased; nn model builds; high variance; computationally expensive; stratified always

Advantages of CV over a single holdout: all data are used both for training and testing; every tuple is tested exactly once; the estimate is less random and its variance can be reported. Limitation: computation ×kk; folds are not independent, so the training sets overlap (breaks strict independence assumptions); for time-series data folds must respect chronological order (forward-chaining / rolling-origin CV).

Stratified kk-fold cross-validation preserves class distribution in each fold — important for imbalanced classes.

4. Bootstrap

The 0.632 bootstrap draws nn tuples with replacement from a dataset of nn tuples; on average only 63.2%63.2\% of the tuples appear in the bootstrap sample, so the rest (≈36.8%\approx 36.8\% or 1−e−11-e^{-1}) form the test set ("out-of-bag" data).

lim⁡n→∞(1−1n)n=e−1≈0.368\lim_{n\to\infty}\Big(1-\frac{1}{n}\Big)^{n}=e^{-1}\approx 0.368

Each tuple has probability 1−(1−1/n)n≈0.6321-(1-1/n)^{n}\approx 0.632 of appearing. Accuracy estimate over bb bootstrap samples, correcting for the optimistic training accuracy:

accboot=1b∑i=1b(0.632×acctest,i+0.368×acctrain,i)\text{acc}_{boot}=\frac{1}{b}\sum_{i=1}^{b}\Big(0.632\times \text{acc}_{\text{test},i}+0.368\times \text{acc}_{\text{train},i}\Big)

Bootstrap is useful for small datasets and also gives standard errors/confidence intervals for almost any statistic; smoothed variants use a weight 1−(1−1/n)n1-(1-1/n)^{n} per tuple.

5. Estimating a Predictor's Accuracy (Numeric)

For numeric predictors, cross-validation and bootstrap are applied with the error measures instead of the accuracy fraction:

MAECV=1k∑i=1kMAEi,RMSECV=1k∑i=1kRMSEi\text{MAE}_{CV}=\frac{1}{k}\sum_{i=1}^{k}\text{MAE}_i,\qquad \text{RMSE}_{CV}=\frac{1}{k}\sum_{i=1}^{k}\text{RMSE}_i
Relative errorCV=1k∑i=1k(∑x∈Di∣y−y^∣∑x∈Di∣y−yˉ∣)\text{Relative error}_{CV}=\frac{1}{k}\sum_{i=1}^{k}\Bigg(\frac{\sum_{x \in D_i}|y-\hat y|}{\sum_{x\in D_i}|y-\bar y|}\Bigg)

The last form is the relative error, which removes the influence of the scale of the target values (used e.g. in the Weka/C4.5 evaluation).

6. Model Comparison — Statistical Significance

kk-fold CV gives kk accuracy estimates per model (not independent!). To compare models A and B on the same folds:

paired t-statistic: t=d‾∑i=1k(di−dˉ)2k(k−1),di=accA,i−accB,i\text{paired } t\text{-statistic: } t=\frac{\overline{d}}{\sqrt{\dfrac{\sum_{i=1}^{k}(d_i-\bar d)^2}{k(k-1)}}},\qquad d_i=\text{acc}_{A,i}-\text{acc}_{B,i}

with k−1k-1 degrees of freedom — reject "models are equal" if ∣t∣|t| exceeds the critical value (this is the cross-validated paired t-test of Dietterich, who also proposes 5×2 CV tt-test, McNemar's test and a test on differences of proportions for more reliable comparisons).

7. Practical Issues in Evaluation

Issue Recommendation
Class imbalance Stratified folds, choose measures like F1/AUC/recall, resample (SMOTE) inside the fold
Data leakage All preprocessing (normalisation, feature selection, discretisation, oversampling) must be fitted inside each fold, not on the whole dataset
Hyper-parameter tuning Use a separate validation set or nested CV so the test set stays untouched
Temporal data Time-ordered (rolling-origin) splits, no random shuffling
Grouped data Group-aware CV so the same patient/customer is not in both train and test
Reporting State the number of folds, the split strategy, mean ± standard deviation, and the metric used

8. Exam Points

  • Explain holdout, random subsampling, cross-validation (kk-fold and LOO) with diagrams and advantages — 10 marks (very frequent).
  • Explain the 0.632 bootstrap and why approximately 63.2% of tuples appear — 5-7 marks.
  • How do you estimate the accuracy of a predictor for numeric prediction (relative error, CV)? — 5 marks.
  • Discuss the paired tt-test for comparing two classifiers — 5 marks.
  • Why is the training-set accuracy not a valid estimate? — 3 marks.
Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.

← All Data Mining modules

Evaluating the Accuracy of a Classifier or Predictor — Data Mining — PYQDeck