← All Posts
Deep Learning · Data Preparation and Preprocessing · Pipelines and Reproducibility

Pipelines and Reproducibility

A model usually consumes a representation built by earlier steps: missing-value replacement, numerical scaling, category encoding, or feature extraction. Those steps belong to the learning procedure and the saved predictor. A preprocessing pipeline keeps their order and fitted state connected to the estimator.

This series explains how to assemble that predictor, evaluate it within the right data boundaries, and preserve enough information to use or repeat it. A pipeline fits the rows you supply; it does not automatically choose a valid split or make every experiment reproducible.

Two kinds of composition

Pipeline is sequential. One step’s output becomes the next step’s input. A mean imputer can fill an age column before a standardizer learns that filled column’s mean and spread.

ColumnTransformer uses separate column branches. An age branch can contain that imputer-and-scaler pipeline, while a city branch learns a one-hot vocabulary. The branches receive their selected raw columns and join their output features for the same rows.

One predictor, nested feature preparation
Outer Pipeline · fit(raw training inputs, targets)
1 · Preprocessing: ColumnTransformer
Age → numerical PipelineImputer.fit_transform↓ filled agesScaler.fit_transform
City → categorical branchOneHotEncoder.fit_transform↓ category indicators
↓ Join feature blocks in their defined order
2 · Estimator: Ridge.fit
Fit learns each branch from the current training rows. Ridge then learns from the joined features and training targets.
The numerical steps form a chain; numerical and categorical branches form separate paths. During prediction, every transformer reuses its saved state before the final estimator predicts.

The sequential example traces four raw training inputs through imputation, scaling, and ridge. The mixed-column example adds a city vocabulary and shows the precise output layout. Follow those examples before adding more transforms.

Keep three data uses distinct

OperationData it may learn fromWhat happens to other rows
Fit a candidate in one CV foldThat fold’s training inputs and permitted training targets.Validation rows use saved transforms and supply a score.
Select a recipeDevelopment data and the declared validation procedure.A separate final test stays outside the selection.
Refit and serve the chosen recipeThe intended final training pool.Future rows are transformed and predicted without fitting new state.

These distinctions prevent a common mistake: fitting preprocessing once on all data and then cross-validating only the estimator. The held-out rows have already influenced that representation. Pass the complete pipeline to the evaluator instead.

Other boundaries still need explicit decisions: whether a user must be unseen, whether a feature existed at the prediction time, and whether a score was used to select a model. Avoiding Leakage with Pipelines supplies a fitted-state audit and links each remaining decision to the relevant split notes.

Preserve both the predictor and the experiment

01Fitted predictorLearned replacement values, scales, vocabulary, estimator state, input schema, and prediction probes.
02Training-run recordData snapshot, ordered split IDs, preprocessing and model configuration, random seeds, code revision, and environment.
Two records serve different purposes. The fitted object supports prediction without retraining. The run record explains how it was obtained and supports a repeat of the learning procedure.

Saving only ridge’s coefficients loses the transformations those coefficients expect. Saving only constructor parameters loses the learned means and vocabulary. Conversely, a complete fitted object does not explain which data and split produced it unless that history is recorded.

A fixed seed also cannot identify a split by itself: a change in row order can assign different records to the same sampled positions. Preserve ordered row identities when you need to replay the same evaluation.

Five chapters, one complete workflow

Build the smallest useful recipe, then extend it

Start with the transformations the data and estimator require. Inspect a small batch before and after each branch, then check the fitted statistics, output width, feature order, and sparse or dense representation. A larger pipeline is easier to understand when every step has a specific purpose.

Keep the choices of transformations tied to their own chapters: missing values, feature scaling, and categorical encoding. This series handles their composition. The cross-validation series handles how the full learning procedure is compared and reported.

References and further reading