Explore Library
Code Quiz

Cross-Validation Data Leakage Bug

Spot the data leakage mistake when scaling features before cross-validation.

Codepython
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_val_score

# Scale all features first
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

model = LogisticRegression()
scores = cross_val_score(model, X_scaled, y, cv=5)
print('CV accuracy:', scores.mean())

What is the bug in this cross-validation setup?