Skip to main content
AI & ML Bug Hunt Medium +20 XP

Data Leakage

This code has data leakage. Find the bug.

AI & MLFind the bug
1scaler = StandardScaler()
2X_scaled = scaler.fit_transform(X)
3X_train, X_test = train_test_split(X_scaled, test_size=0.2)
The bug is on line 2

Select the correct fix

Show answer and explanation

Answer: Fit scaler on training data only, then transform test data separately

Scaling before splitting leaks test data statistics into training. Always split first, then fit_transform on train, transform on test.

Hint: Test data should never influence preprocessing parameters.

What this challenge tests

Bug Hunt in AI & ML: data-leakage, preprocessing.

Related challenges