Min-Max Scaling with Training Stats

Easy
~15 min
code completion

Min-Max Scaling with Training Stats

Min-max scaling (normalization) transforms each feature to the range by mapping the training minimum to 0 and the training maximum to 1:

As with standardization, you must fit on X_train only and apply the same parameters to X_test — otherwise test information leaks into your scaler.

Edge case: If a column is constant (max == min), set the denominator to 1 to avoid division by zero. All values map to 0.

Example:

X_train = [[0, 10], [4, 20]]    → per-col min=[0,10], max=[4,20]
X_test  = [[2, 15]]             → scaled: [(2-0)/(4-0), (15-10)/(20-10)] = [0.5, 0.5]

Your task:

Implement minmax_scale(X_train, X_test) that returns the min-max scaled version of X_test.

Example Tests

2-feature test: midpoints map to 0.5

Input: {"X_test":[[2,15]],"X_train":[[0,10],[4,20]]}

Expected: [[0.5,0.5]]

Test point at train min gives 0.0, at train max gives 1.0

Input: {"X_test":[[0],[10]],"X_train":[[0],[10]]}

Expected: [[0],[1]]

Constant column: denominator replaced by 1, output is 0.0

Input: {"X_test":[[5]],"X_train":[[5],[5]]}

Expected: [[0]]

Sign in to solve this problem

You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.