Problem 3: Correctly Scale Training and Test Sets Separately
Easypython
Learn the Concept: Feature ScalingProblem 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.
Related Problems
- Problem 1: Apply Standardization to a DatasetEasy · pythonSolve Problem
- Problem 2: Apply Normalization to a DatasetEasy · pythonSolve Problem
- Problem 4: Compare Standardization vs Normalization on the Same DataEasy · pythonSolve Problem