Two students build the same k-nearest-neighbors churn model. Student A calls StandardScaler().fit_transform(X) on the full dataset and then splits into train and test. Student B splits first and puts the scaler inside a Pipeline with the model.
What is wrong with Student A's approach?
Why did you pick that answer? Two or three sentences. The act of articulating it is what builds the judgment — not the click that follows.
Fitting any preprocessing step on all rows leaks information about the test distribution into the training pipeline. The effect for scaling is small, but the same habit with imputers, target encoders, or feature selectors can leak a lot. A Pipeline fit on the training fold guarantees every step sees only training data — which is exactly what happens in production.
A scaler learns parameters (mean, std) from data. Anything learned must be learned on training data only.
kNN is one of the models most sensitive to scale: a feature measured in dollars will dominate one measured in years.
In production you score one customer at a time — there is no test set to fit on. Parameters must come from training.