Definition
The placebo keeps the inputs, the code and the evaluation, and breaks the only thing a model is supposed to learn: the link between the inputs and the target. The target column is permuted at random. Repeated many times, this is the permutation test of Ojala and Garriga, and the scores obtained form the distribution of what the pipeline produces when there is nothing to find.
The test is run on the full procedure: feature construction, selection, tuning and scoring. A placebo applied to the last step only would miss the leaks that sit upstream.
Worked example
Two pipelines are given real data with a weak signal, then the same data with shuffled labels. One of them selects features before cross-validation.
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score
from sklearn.pipeline import make_pipeline
rng = np.random.default_rng(8)
X = rng.normal(size=(150, 2000))
y = (X[:, 0] + rng.normal(scale=2.0, size=150) > 0).astype(int) # one weakly useful feature
def leaky(X, y):
Xs = SelectKBest(f_classif, k=15).fit_transform(X, y) # sees the test folds
return cross_val_score(LogisticRegression(), Xs, y, cv=5, scoring="roc_auc").mean()
def clean(X, y):
pipe = make_pipeline(SelectKBest(f_classif, k=15), LogisticRegression())
return cross_val_score(pipe, X, y, cv=5, scoring="roc_auc").mean()
for name, f in [("selection outside the folds", leaky), ("selection inside the folds", clean)]:
placebo = [f(X, rng.permutation(y)) for _ in range(10)]
print(f"{name:28s} AUC on real labels = {f(X, y):.2f} mean AUC on shuffled labels = {np.mean(placebo):.2f}")Output, produced by running the code above when this page was built:
selection outside the folds AUC on real labels = 0.88 mean AUC on shuffled labels = 0.86 selection inside the folds AUC on real labels = 0.58 mean AUC on shuffled labels = 0.47
On real labels the first pipeline looks much better than the second. The placebo shows why: it scores far above 0.5 on labels that carry no information. The second pipeline returns to chance level on the placebo, and its lower score on real labels is the honest one.
Where it misleads
- Shuffling destroys the structure of the target as well as its link with the inputs. On time series, a plain permutation removes autocorrelation; shuffle blocks, or shift the target in time, to keep it.
- The placebo detects leaks that pass through the target. A feature that contains the outcome stays with the inputs when the labels are shuffled, and goes unnoticed. That case needs a review of where each feature comes from.
- Passing the placebo does not prove the model is good. It only says the pipeline does not manufacture a score from nothing.
- A few runs are not enough to see a small leak. The spread of the placebo scores gives the resolution of the test.
The placebo has a mirror image, the positive control: plant a known effect and check that the pipeline finds it.
In our work
A placebo is one of the three development checks every result of ours has to pass, with a paired gain and a planted effect. In our credit validation report, 20 placebo models reached a mean AUC of 0.496.
Service: machine learning and model validation Research note: our gates Research note: credit model validation, a worked report
References
- Ojala, M., Garriga, G. C. (2010). Permutation tests for studying classifier performance. Journal of Machine Learning Research, 11, 1833-1863. www.jmlr.org/papers/v11/ojala10a.html
- Kapoor, S., Narayanan, A. (2023). Leakage and the reproducibility crisis in machine-learning-based science. Patterns, 4(9), 100804. doi:10.1016/j.patter.2023.100804
- Kaufman, S., Rosset, S., Perlich, C., Stitelman, O. (2012). Leakage in data mining: formulation, detection, and avoidance. ACM Transactions on Knowledge Discovery from Data, 6(4), 1-21. doi:10.1145/2382577.2382579