AI & ML Bug Hunt Medium +20 XP
Data Leakage
This code has data leakage. Find the bug.
AI & MLFind the bug
1
scaler = StandardScaler()2
X_scaled = scaler.fit_transform(X)3
X_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.