Skip to content
AI.info

Classical machine learning

Pipelines, Baselines, and Preprocessing Boundaries

Build leak-resistant preprocessing pipelines, baseline ladders, and sanity checks for classical machine-learning experiments.

By the end you can

Key idea

Preprocessing is part of the model

Imputation, scaling, encoding, feature selection and dimensionality reduction all learn information from data. If any of them sees validation or test rows while it is being fitted, the evaluation no longer represents an unseen sample.

Treat the complete transformation-plus-estimator chain as one fitted object.

A clean estimator inside a leaky pipeline is still a leaky model.

Comparison

A baseline ladder with different purposes

One baseline rarely answers every question.

The top rung of that ladder has been measured. In 2014 Fernández-Delgado and colleagues ran “179 classifiers arising from 17 families”, implemented in Weka, R, C and Matlab. The test bed was “121 data sets, which represent the whole UCI data base (excluding the large-scale problems) and other own real problems”. The winner was a random forest, reached through R’s caret package. It “achieves 94.1% of the maximum accuracy overcoming 90% in the 84.3% of the data sets”. The runner-up was a Gaussian-kernel support vector machine in C, using LibSVM. That one “achieves 92.3% of the maximum accuracy”. The difference between the two was not statistically significant.

A strong classical baseline is not a courtesy paid to the reader. It is the number a new method has to beat.

FigureComparison · 4 columns

Policy baseline

Reproduces the existing rule or human process.

  • Measures value over current operations
  • Exposes hidden business logic
  • May include inconsistent human behavior
  • Defines the practical challenger

Constant baseline

Predicts a mean, median, prevalence, or majority class.

  • Tests whether features add signal
  • Provides a metric floor
  • Can reveal metric misuse
  • Must respect grouping and weighting

Simple statistical baseline

Uses a small regularized linear model or shallow tree.

  • Tests broad relationships
  • Surfaces preprocessing errors
  • Supports coefficient or rule inspection
  • Often hard to beat on clean tabular data

Strong classical baseline

Uses a tuned forest, kernel method, or additive model.

  • Sets a credible performance target
  • Captures nonlinear structure
  • Increases tuning burden
  • Still requires valid pipeline boundaries

Visual

The fitting boundary of a valid pipeline

Every data-dependent step belongs inside resampling and must be refit on each training fold.

That boundary is not a workshop convention. It is written into medical-device guidance. On 27 October 2021 three regulators — the US FDA, Health Canada and the UK MHRA — jointly issued ten Good Machine Learning Practice guiding principles for medical device development. The fourth is titled “Training Data Sets Are Independent of Test Sets”, and it reads as a requirement rather than a suggestion: “Training and test datasets are selected and maintained to be appropriately independent of one another. All potential sources of dependence, including patient, data acquisition and site factors are considered and addressed to assure independence.”

The second sentence is the one that costs work. Independence is not obtained by drawing a random split. It is obtained by naming every channel through which a held-out row could already be represented in the training data — the same patient, the same acquisition, the same site — and closing each one before a single transformation is fitted. A regulator deciding whether a device is safe does not accept a pipeline whose boundary was assumed. Neither should the person who built it.

FigureProcess · 5 steps
  1. 1

    Raw training fold

    Rows and targets selected without using held-out outcomes.

  2. 2

    Fit transformations

    Learn imputers, category maps, scalers, selectors, or encoders.

  3. 3

    Transform fold

    Apply only parameters learned from that fold.

  4. 4

    Fit estimator

    Learn coefficients, rules, neighbors, or support vectors.

  5. 5

    Evaluate held-out rows

    Apply the frozen pipeline once to unseen data.

Different algorithms need different preparation

Distance and margin methods are sensitive to feature scale. Trees usually do not need standardization, but they still depend on missing-value handling, category representation and valid splits.

Linear models can use one-hot, ordinal, spline or target-derived features. Each encoding changes the function the model can express.

Example

Four quiet ways a pipeline contaminates evaluation

Leakage enters through respectable preprocessing, not through an obvious target column. The scale of it has been counted rather than guessed at. Kapoor and Narayanan surveyed the fields that had taken up machine learning and published the audit in Patterns in 2023: “Through a survey of literature in fields that have adopted ML methods, we find 17 fields where leakage has been found, collectively affecting 294 papers and, in some cases, leading to wildly overoptimistic conclusions.” They sort the failures into eight distinct types. This is not a beginner’s mistake being described. It is 294 published papers across 17 fields, each of which passed review.

One of those channels has been measured on data that contained nothing at all. Vandewiele and colleagues drew 10,000 five-dimensional points from a uniform distribution and labelled them at random. Then they applied over-sampling before partitioning. Their 2021 paper reports what came out: “Nevertheless, due to applying the Synthetic Minority over-sampling Technique (SMOTE) before data partitioning, an Area Under the receiver operating characteristic Curve (AUC) of 0.95 on a ‘held-out’ testing set can be achieved. This in contrast to an AUC of 0.49 and 0.48 when applying no SMOTE or SMOTE after data partitioning respectively, which closely resembles random guessing.”

On real data the same misplacement carries a price you can quote. Demircioğlu tested four over-sampling methods on 15 public radiomic datasets in 2024. The biases reached 0.34 in AUC, 0.33 in sensitivity, 0.31 in specificity and 0.37 in balanced accuracy.

0.95 against 0.49 in the same coin-flip data is the number to carry out of this section. Every item below is a different route to it.

  • Global imputation: a median computed using the full dataset lets held-out values influence the training transformation.
  • Feature selection before cross-validation: outcome correlations from validation folds determine which columns the model receives.
  • Target encoding without cross-fitting: each row partly contributes to the statistic used to encode its own category.
  • Oversampling before the split: synthetic or duplicated minority examples can appear in both training and validation — the route that reached an AUC of 0.95 on randomly assigned labels.
  • Vocabulary construction on all text: held-out token occurrence changes the representation even when labels remain hidden.

Steps

Build the first trustworthy experiment

The aim is not maximum accuracy. It is a result you can believe.

Step 2 is the one usually settled by convenience, and its cost has been measured. Deep-learning models can identify the tissue-submitting site of a slide in The Cancer Genome Atlas. Across more than 3,000 patients and six cancer subtypes, they do it with AUROC between 0.964 and 0.998. Standard colour normalisation and augmentation do not remove the signal. Howard and colleagues showed that in Nature Communications in 2021, and priced it: enforcing site-preserved cross-validation lowered AUROC by 0.069 on average, with 91.1% of predictable features declining. Their abstract states the consequence: “These site-specific signatures can lead to overoptimistic estimates of model performance, and we propose a quadratic programming method that abrogates this bias by ensuring models are not trained and validated on samples from the same site.”

The same thing had turned up three years earlier in a different modality. Zech and colleagues reported in PLOS Medicine in 2018 that convolutional networks identified the hospital system of a chest radiograph for 99.95% of NIH images and 99.98% of Mount Sinai images. A model with an internal AUC of 0.931 fell to 0.815 externally. A split chosen at random hands the model a shortcut and then congratulates it for taking one.

A control can carry a p-value instead of an impression. Ojala and Garriga set out two permutation tests in 2010. The first asks “whether the classifier has found a real class structure in the data”. It estimates its null distribution “by permuting the labels in the data”. The second asks “whether the classifier is exploiting the dependency between the features in classification”. It permutes the features within classes instead, which leaves each class’s marginal distributions intact. The two tests name two different failures. One is no signal at all. The other is a model that never used the structure you believed it used. A single accuracy figure cannot tell them apart.

FigureProcess · 6 steps
  1. 1. Freeze the prediction contract

    Confirm row meaning, cutoff, target, groups, and exclusions.

  2. 2. Choose a split strategy

    Match time, entity, site, or deployment boundaries.

  3. 3. Implement the constant baseline

    Verify metric calculation and target prevalence.

  4. 4. Fit one transparent pipeline

    Keep every learned transformation inside the training fold.

  5. 5. Inspect individual errors

    Check raw rows, transformed values, and impossible predictions.

  6. 6. Record the experiment

    Save code, data version, features, split, settings, and results.

Analogy

A cooking contest with sealed ingredient boxes

Each contestant in a cooking contest receives a sealed box of training ingredients. The recipe must be prepared before the judging box is seen. Measuring, tasting or selecting spices from the judging box would invalidate the contest.

A contest is judged once. Cross-validation repeats it with several boxes, and each round must relearn every data-dependent preparation step.

Held-out data may be transformed, but it must not teach the transformation.

Sanity checks should be able to make the model fail

Shuffle the labels and confirm that performance collapses. Remove a suspicious feature and measure the change. Train on a tiny subset and see whether the pipeline can overfit it when the model has enough capacity.

A workflow that cannot detect deliberately broken data is not ready to certify an improvement.

Positive results become credible only after negative controls behave as expected.

Case

Permuted labels still produced a near-zero cross-validated error on 2,000 genes

The demonstration is old and it is brutal. In 2002 Ambroise and McLachlan took the colon-cancer microarray data — 62 tissue samples, 2,000 genes — and destroyed the signal in it. They permuted the class labels at random, twenty times over. On those no-information sets they still selected genes by recursive feature elimination and fitted a support vector machine. Their PNAS paper reports a rule with “not only an average zero AE but also an average CV1IE error close to zero for a subset of 128 genes”: zero apparent error on the training tissues, and a leave-one-out cross-validated error near zero, on labels that were noise.

The estimates that repeat the gene selection inside every fold — 10-fold cross-validation and the .632+ bootstrap — came out, on the same sets, “between 0.40 and 0.45”. That, they write, is “consistent with the fact that we are forming a prediction rule on the basis of a no-information training set”. Their conclusion is this section’s rule stated as a finding: “an internal cross-validation does not suffice.”

Position

The two experiments that can only produce bad news are the two nobody runs

A project log will hold dozens of runs that could raise the score and, more often than not, neither of the two that could lower it. Both are cheap. Both are in this lesson. Both exist to tell you something you would rather not hear.

The first is the negative control. Ambroise and McLachlan permuted the class labels of 62 colon tissue samples twenty times over, destroying whatever signal was there. Then they selected genes and fitted a support-vector machine the way the published papers had. They got a leave-one-out cross-validated error close to zero on a subset of 128 genes. On the same no-information sets, with the gene selection repeated inside every fold, the estimates come out between 0.40 and 0.45. What that comparison isolates is not carelessness but a boundary: “an internal cross-validation does not suffice”, and where the selection sits relative to the fold is what decides the number. The pair of permutation tests from Ojala and Garriga then separates the two failures one accuracy figure cannot tell apart — no class structure at all, and a classifier that never used the dependency you believed it was using.

The second is the baseline, and it has to be a tuned one. Across the 179 classifiers and 121 data sets that Fernández-Delgado and colleagues ran, the best random forest reached 94.1% of the maximum accuracy available and a Gaussian-kernel SVM 92.3%. The gap was not statistically significant. That is the standard a challenger claims to be worth more than, and when someone goes back and applies it, the challenger frequently loses. In 2019 Ferrari Dacrema and colleagues took 18 top-n recommendation algorithms published at top-level conferences and tried to rerun them: “Only 7 of them could be reproduced with reasonable effort. For these methods, it however turned out that 6 of them can often be outperformed with comparably simple heuristic methods, e.g., based on nearest-neighbor or graph-based techniques.” The following year four researchers at Google re-ran the experiments of the neural collaborative filtering paper. With proper hyperparameter selection, a simple dot product substantially outperformed the learned similarities it had been reported to lose to.

Eighteen methods, seven reproducible, six of those beaten by a neighbourhood heuristic. A baseline fitted once at default settings, in order to be beaten, does not measure the claim being made about it. It decorates it.

A baseline that was configured to lose is not a control. It is a prop.

Key idea

Do not tune before the experiment is trustworthy

Large searches can optimize leakage, split artifacts or metric noise. They do it more efficiently than a simple model. Tuning should begin only after baselines, controls and error inspection agree that the signal is real.

The search is itself a data-dependent step, so it belongs inside the resampling boundary like every other. Varma and Simon stated the finding in one sentence in 2006: “We show that using CV to compute an error estimate for a classifier that has itself been tuned using CV gives a significantly biased estimate of the true error.” Their evidence is the null case. On datasets built with no real class difference, the cross-validated error estimate for a tuned Shrunken Centroid classifier fell below 30% on 18.5% of simulated training sets. For a tuned SVM it fell below 30% on 38% of null sets. Performance on independent test data was no better than chance.

The same bias shows up in kernel ridge regression. Cawley and Talbot measured it in 2010 across thirteen benchmark datasets, and found the external protocol optimistic on all thirteen: on breast cancer, 26.280% ± 0.232 error against the internal protocol’s 27.470% ± 0.250, a bias of 1.190 ± 0.135 percentage points. Nesting the tuning inside an outer resampling loop is what repairs it.

The first objective is epistemic: know why you believe the score.

A reliable baseline is an instrument for reasoning, not a weak model to discard quickly.

Key takeaways