Tutorials › Exam PA - Predictive Analytics › Early Stopping Without Test-Set Reuse

Exam PA · Gradient Boosting and Tuning · Tutorial 565 of 966

Early Stopping Without Test-Set Reuse

Set a defensible stopping rule for boosting, select the iteration using validation data, and reserve test data for final assessment.

Advanced 10 min read

What You'll Learn

  • Distinguish the roles of training, validation, and test data during boosting.
  • Define a validation-loss improvement rule using a minimum gain and patience.
  • Track the selected iteration separately from the iteration at which training stops.
  • Calculate validation MSE and test RMSE from predictions.
  • Explain how selecting a model on test performance compromises final assessment.
  • Identify when splitting, preprocessing, or repeated test use can cause leakage.

Why Early Stopping Needs Its Own Data

Gradient boosting builds an additive model one tree at a time. As covered in the earlier material on choosing the number of boosting iterations, the number of trees affects model complexity: adding trees can initially improve predictions, but continuing indefinitely can make performance on new data worse. Early stopping uses a monitored loss to decide when to stop building trees and which iteration to retain.

The crucial design choice is which observations supply that monitored loss. Training loss is generally not a suitable stopping signal by itself: the boosting procedure is fitting the training data, so its loss can keep falling even while generalization is no longer improving. A validation set provides a separate signal for the stopping decision. A test set has a different job: it is held back until the modeling decisions are complete, then used for final performance assessment.

Definition: The training set is used to fit the boosting model. The validation set is used during model development to monitor performance and make decisions such as when to stop. The test set is reserved for assessing the final, prespecified modeling procedure. If test results influence a modeling decision, the test set has been used for development and is no longer an untouched final assessment set.

For early stopping, the usual setup is to fix the other modeling choices for the run and evaluate a chosen loss on validation observations after each boosting iteration. Those observations must not also have been used to fit the trees. If several modeling choices are being compared, the validation set still serves development; repeated decisions based on it can make validation performance optimistic. The test set remains separate from all such decisions.

Specify the Stopping Rule Before Fitting

Let \(L_m\) denote the validation loss after \(m\) boosting iterations. For squared-error regression, one common choice is mean squared error (MSE). If the validation responses are \(y_i\) and the predictions after iteration \(m\) are \(\hat{y}_{im}\), then

$$ L_m = \frac{1}{n_{\mathrm{val}}}\sum_{i=1}^{n_{\mathrm{val}}}(y_i-\hat{y}_{im})^2. $$

This loss is appropriate when squared prediction errors are the intended measure of performance. Other prediction tasks require a loss aligned with the target, such as a classification loss. The validation observations, loss definition, and any minimum-improvement threshold should be specified before examining test results.

A practical stopping rule can use a minimum improvement \(\varepsilon \geq 0\) and a patience value \(r\), a positive integer. In the convention used here, an iteration qualifies as an improvement only when its loss is strictly less than the best qualifying loss so far by more than \(\varepsilon\). Each qualifying iteration becomes the new selected checkpoint and resets the wait count. Each iteration that does not qualify increases the wait count by one. Stop when the wait count reaches \(r\), or when the prespecified maximum number of iterations is reached.

Definition: Let \(B\) be the best qualifying validation loss so far. An iteration \(m\) qualifies if \(L_m < B-\varepsilon\). The first available iteration initializes \(B\). When an iteration qualifies, set \(B=L_m\), record \(m\) as the selected iteration, and reset the wait count to zero. Otherwise, increase the wait count by one. Stop after \(r\) consecutive nonqualifying iterations. The selected iteration is the most recent qualifying checkpoint—not necessarily the iteration at which stopping occurs.

With \(\varepsilon=0\), any strict decrease qualifies; an equal loss does not. A positive \(\varepsilon\) prevents tiny fluctuations from repeatedly resetting patience. The threshold is measured in the units of the chosen loss, so it is not automatically comparable across different loss definitions or response scales. The stopping rule is a protocol, not a universal law: implementations may use different conventions, and the convention in use must be understood before interpreting a reported stopping iteration.

Worked Example: Selecting a Checkpoint From Validation MSE

A hypothetical provider is building a boosting model to predict the cost of equipment repairs. For four validation cases, the observed costs, in thousands of dollars, are \(10, 12, 14,\) and \(16\). Predictions at three iterations are shown below. Use validation MSE to select an iteration, taking the earliest iteration in the event of a tie.

IterationPredictions, in thousands of dollars
111, 11, 15, 15
210, 13, 13, 16
310.5, 12, 14.5, 16

Method. Calculate the squared error for each validation case at each iteration, average the four squared errors, and select the iteration with the smallest MSE.

At iteration 1, the prediction errors are \(10-11=-1\), \(12-11=1\), \(14-15=-1\), and \(16-15=1\). The squared errors are \(1,1,1,1\), so \(L_1=(1+1+1+1)/4=1\).

At iteration 2, the errors are \(0,-1,1,0\), and the squared errors are \(0,1,1,0\). Thus \(L_2=(0+1+1+0)/4=0.5\).

At iteration 3, the errors are \(-0.5,0,-0.5,0\), and the squared errors are \(0.25,0,0.25,0\). Thus \(L_3=(0.25+0+0.25+0)/4=0.125\).

The validation MSE falls from \(1\) to \(0.5\) to \(0.125\), so iteration 3 is selected. Check: all three losses are averages of four squared errors, and the smallest is \(0.125\). The common mistake avoided is choosing from training loss or simply retaining the last iteration without checking validation performance.

Why the Validation Set Must Be Separate

At each boosting iteration, the fitted model depends on the training data. The validation observations then provide an out-of-training-sample signal for comparing the successive fitted models. This does not make validation performance a final independent assessment: the analyst has examined it repeatedly and used it to choose an iteration.

The test set addresses a different question: how does the completed modeling procedure perform on observations that did not influence fitting or model selection? The distinction matters even if the same loss is calculated on both sets. A validation loss can guide a stopping decision; a test loss should not.

1
Separate the data.
Allocate training, validation, and test observations before making model-selection decisions. Choose a split appropriate to the data structure; for example, observations ordered in time may require a time-based split rather than a random one.
2
Fit and monitor.
Fit boosting using the training observations. After each iteration, calculate the prespecified validation loss and apply the stated improvement and patience rules.
3
Retain the selected checkpoint.
Keep the model at the qualifying iteration selected by the validation rule, even if the run continues for additional iterations before patience is exhausted.
4
Assess once on test data.
After the model and its selected iteration are fixed, calculate the final test performance. Do not change the model in response to that result and continue to describe the test set as untouched.

The separation must apply to preprocessing as well as tree fitting. Any transformation that learns quantities from data—such as imputation values or scaling parameters—should be estimated using training data and then applied to validation and test data. Otherwise, information from the held-out observations can enter the modeling process before a prediction is evaluated. The same principle applies to repeated test-set inspection: trying several versions and reporting only the most favorable test result is a form of test-set reuse.

Justification: Why Choosing on Test Loss Is Optimistic

Suppose a developer calculates test loss for several candidate models and reports the model with the smallest test loss. Even if each candidate’s test loss is individually reasonable, the smallest observed value tends to be favorably affected by sampling noise. The basic inequality explains the direction of the effect.

Let \(\hat{R}_j\) be the estimated test loss for candidate \(j\), and let \(R_j\) be its expected loss. For each candidate, the minimum across all candidates cannot exceed that candidate’s own estimated loss. Taking expectations gives \(E[\min_j \hat{R}_j]\leq E[\hat{R}_k]=R_k\) for every \(k\), when each estimate targets its candidate’s expected loss. Therefore,

$$ E\!\left[\min_j \hat{R}_j\right] \leq \min_j R_j. $$

The reported minimum is thus, on average, no larger than the smallest candidate’s expected loss. This argument does not require independent candidate estimates. It explains why using test loss to choose a candidate makes the reported selected loss optimistic as an assessment of future performance. Validation data are intended for such choices; the test set is retained to assess the procedure after those choices are complete.

Worked Example: Patience Is Not the Selected Iteration

A hypothetical model for predicting the duration of equipment inspections is monitored using validation loss. The losses after successive iterations are \(0.90, 0.80, 0.795,\) and \(0.792\). Use an absolute minimum improvement of \(\varepsilon=0.01\) and patience \(r=2\). Apply the strict rule \(L_m < B-\varepsilon\). Identify where the run stops and which iteration is selected.

Method. Track the best qualifying loss \(B\), the selected iteration, and the consecutive nonqualifying count separately.

Iteration 1 initializes the rule: \(B=0.90\), selected iteration \(1\), and wait count \(0\).

At iteration 2, \(0.80 < 0.90-0.01=0.89\), so it qualifies. Set \(B=0.80\), select iteration \(2\), and reset the wait count to \(0\).

At iteration 3, the qualifying threshold is \(B-\varepsilon=0.80-0.01=0.79\). Since \(0.795\) is not less than \(0.79\), iteration 3 does not qualify; the wait count becomes \(1\).

At iteration 4, the threshold remains \(0.79\). Since \(0.792\) is not less than \(0.79\), iteration 4 also does not qualify. The wait count becomes \(2\), so patience is exhausted and the run stops at iteration 4. The selected iteration remains iteration 2. Check: the run stops after two consecutive failures to improve by more than \(0.01\); stopping at iteration 4 does not make iteration 4 the selected checkpoint. The common mistake avoided is treating the stopping point as the best checkpoint.

Final Test Assessment and Practical Limits

Once the stopping protocol has selected an iteration, apply the final model to the untouched test observations and calculate the prespecified performance measure. For regression, the test MSE is the average squared prediction error; the root mean squared error (RMSE) is its square root and is on the response scale. Report which data were used to select the iteration and which were used for final assessment.

Worked Example: Calculate Final Test RMSE Without Retuning

For a hypothetical model predicting inspection duration in hours, a dedicated validation set has selected iteration 3. The test residuals, defined as observed duration minus predicted duration, are \(1,-1,2,0,\) and \(-2\) hours. Calculate test MSE and RMSE, and state whether these results should change the selected iteration.

Method. Square each test residual, average the squared values to obtain MSE, and take the square root to obtain RMSE.

The squared residuals are \(1^2=1\), \((-1)^2=1\), \(2^2=4\), \(0^2=0\), and \((-2)^2=4\). Their sum is \(1+1+4+0+4=10\). With five test observations, the test MSE is \(10/5=2\) hours squared. The test RMSE is \(\sqrt{2}=1.4142\) hours, rounded to four decimal places.

Iteration 3 remains selected because the test set is for final assessment, not further selection. Check: the squared errors sum to \(10\), and squaring the reported RMSE gives approximately \(2\). The common mistake avoided is using test results to select a different iteration after seeing its performance.

There are practical limits to what early stopping establishes. A patience rule can stop before a later improvement occurs; increasing patience or the maximum iteration count changes the procedure. A validation set that is too small or unrepresentative can give a noisy stopping signal. Also, if the selected model is later refit using both training and validation observations, the fitted sequence of trees may differ from the original sequence. That refit should be treated as a distinct, prespecified procedure, and the test set should still be evaluated only after it is fixed.

For a defensible analysis, document the data split, monitored loss, improvement threshold, patience, selected iteration, and final test metric. This makes clear that stopping was driven by validation evidence and that test performance was not used to tune the reported model. These distinctions are aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Key takeaway: Use validation loss and a stated patience rule to choose the boosting checkpoint. The iteration at which patience is exhausted can be later than the selected checkpoint. Preserve the test set for the final assessment, and do not revise the model after examining that assessment.

Check Your Understanding

For each question, apply the stated loss and stopping convention carefully.

  1. A validation set has losses \(0.42, 0.37,\) and \(0.39\) at iterations 1, 2, and 3. With no positive minimum-improvement threshold, which iteration has the smallest observed validation loss? (Answer: iteration 2.)
  2. Use \(\varepsilon=0.005\), patience \(r=2\), and the strict rule \(L_m < B-\varepsilon\). The losses at iterations 1 through 5 are \(0.50, 0.48, 0.478, 0.474,\) and \(0.473\). At the end of iteration 5, which iteration is selected, and has patience triggered? (Answer: selected iteration 4; patience has not triggered.)
  3. Use \(\varepsilon=0.02\) and patience \(r=2\). Validation losses are \(0.70, 0.60, 0.59, 0.585,\) and \(0.57\). Apply the strict improvement rule. At what iteration does the run stop, and which iteration is selected? (Answer: the run stops at iteration 4; iteration 2 is selected.)
  4. A selected model has test residuals \(2,-1,1\). Calculate test MSE and RMSE, rounding RMSE to four decimal places. Should the result be used to choose another iteration? (Answer: MSE \(=2\); RMSE \(=1.4142\); no, the test result should not be used to retune.)
  5. A team calculates test loss after every iteration and selects the iteration with the smallest test loss. What is the problem with reporting that minimum as final test performance? (Answer: the test set has been used for model selection, so the selected minimum is optimistically biased and is not an untouched final assessment.)
Clinical Biostats