Fitting Preprocessing on Training Data
Any transformation that estimates parameters from examples needs a fitting boundary. Reuse those fitted parameters when transforming held-out inputs.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace a scale change
Training values 2 and 6 have mean four. A held-out value of ten can be centered to six by subtracting that mean. Recomputing the mean from all three would change both features and evaluation. See feature standardization.
Test the full pipeline
Verify that the same trained transformation is loaded for actual predictions. Pipeline stage types help check dimensions as well as values.[1][2]
Freeze the transformation before applying it to held-out data
A training set with values two and six has mean four. Centering a test observation ten by the saved training mean gives six. Including ten when fitting the mean gives six as the mean and four as the transformed test value, changing the procedure. See standardization with training statistics.
Fit on train: center=4
Transform train: [-2,2]
Transform held-out 10: 6
Never refit on that held-out example for this evaluation
Put learned preprocessing inside each training fold
Vocabulary, missing-value fills and feature selection can also learn from data. Verify the full pipeline fits these only on allowed rows. Test a held-out value far outside training range.