QuestionQ82

VerifiedData Processing

A data scientist is using Spark ML to engineer features for an exploratory machine-learning project. They want to standardize the features with the following code block:

Question Image

During code review, a colleague raises a concern that the features are standardized before the data is divided into training and test sets. Which change can the data scientist make to address this concern?

Explanation

StandardScaler is an estimator that computes feature summary statistics when it is fit. Fitting it before the split lets test-set values influence the scaling parameters, causing data leakage. Fit a Pipeline containing the scaler on the training data and use the resulting PipelineModel to transform the test data, so test features are scaled using only the training data’s summary statistics.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!