Scaling Train and Test Data
Spot the data-leakage bug when scaling features for train and test sets.
Codepython
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)
# scale the test set
X_test_scaled = scaler.fit_transform(X_test)
model.fit(X_train_scaled, y_train)
model.score(X_test_scaled, y_test)
What is the bug in this feature-scaling code?