Problem 3: Correctly Scale Training and Test Sets Separately
Easypython
Problem Description
Write a Python program that splits a dataset into training and test sets, fits a StandardScaler on the training set only, and then applies that same fitted scaler to both the training and test sets.
Input
A dataset with one numeric feature column, split into training and test portions.
Output
The scaled training and test sets, using parameters learned only from the training data.
Constraints
- Assume the split has already been performed (or perform it using
train_test_split).
Example Input
textfeature = [10, 20, 30, 40, 50, 60]
Example Output
text(Scaled training set values, and scaled test set values using the SAME scaler fitted only on training data)
Concepts Covered
StandardScaler, .fit() vs .transform(), avoiding data leakage.