The scaler that learns from the test set
A scientific-ML preprocessing step lets validation and test extrema alter the feature scale learned from training data.
What’s going wrong
Original ML practice for ML4SCI contribution preparation; not an upstream bug reproduction. This independent teaching scenario practices a preprocessing invariant useful in scientific machine learning. It is not an official selection task.
The rows have already been separated into training, validation and test subsets, but a min-max scaler combines them when learning feature extrema. An outlier in held-out data changes the training values themselves. Repair scale_features so all three subsets use one transform fitted exclusively on train.
Input is {"train":[[0,10],[10,20]],"validation":[[5,15]],"test":[[20,0]]}. Each array is a matrix: rows are examples and columns are independent features. For each column j, let low[j] and high[j] be the minimum and maximum among training rows only. Its divisor is high[j]-low[j], except a zero range uses 1. Transform every entry x in that column as (x-low[j])/divisor[j], using the same low and divisor for training, validation and test. Round each final transformed entry with Python round(value, 6). Do not clip values: held-out entries may legitimately produce values below 0 or above 1.
Print an object with the same train, validation and test matrix structure, preserving subset, row and column order. Training has 1 to 100 rows; validation and test each have 0 to 100 rows. Every row has the same width from 1 to 8 columns. All feature values are integers from -1000 to 1000. Inputs satisfy these bounds and contain no missing or nonfinite values. Fit extrema once from train; empty held-out matrices remain empty.
Expected behavior
Learn each feature minimum and range from training rows alone, then reuse that transform for every subset with zero-range divisor one, six-decimal rounding and no clipping.
Reproduction
{"train":[[0,10],[10,20]],"validation":[[5,15]],"test":[[20,0]]}{"train":[[0.0,0.0],[1.0,1.0]],"validation":[[0.5,0.5]],"test":[[2.0,-1.0]]}{"train":[[0,0],[10,10]],"validation":[[5,5]],"test":[[2,8]]}{"train":[[0.0,0.0],[1.0,1.0]],"validation":[[0.5,0.5]],"test":[[0.2,0.8]]}{"train":[[4,10],[4,20]],"validation":[[6,15]],"test":[[3,30]]}{"train":[[0.0,0.0],[0.0,1.0]],"validation":[[2.0,0.5]],"test":[[-1.0,2.0]]}Before you begin
- Nested lists and columns
- Min-max scaling
- Training and held-out data
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.