Min-Max Scaling with Training Stats
~15 mincode completion
Implement minmax_scale(X_train, X_test) that returns the min-max scaled version of X_test.
Examples
2-feature test: midpoints map to 0.5
- Input
- minmax_scale([[0, 10], [4, 20]], [[2, 15]])
- Output
- [[0.5, 0.5]]
Test point at train min gives 0.0, at train max gives 1.0
- Input
- minmax_scale([[0], [10]], [[0], [10]])
- Output
- [[0], [1]]
Constant column: denominator replaced by 1, output is 0.0
- Input
- minmax_scale([[5], [5]], [[5]])
- Output
- [[0]]
Hints
Hint 1
picks between two values elementwise without branching.
Hint 2
Reach for train min max rather than test min max.
Requirements
X_train: Training features, shape (n_train, d)X_test: Test features, shape (n_test, d)Return Scaled X_test of shape (n_test, d), values in [0, 1] for in-distribution inputs.
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~15 min
••••••••••••••••
8 employers weight this skill
3 AI product companies, 2 big tech firms, 2 enterprise vendors, 1 defense company. Top match scores 87.
Python
import numpy as np
def minmax_scale(X_train: np.ndarray, X_test: np.ndarray) -> np.ndarray:
"""
Scale X_test to [0, 1] using per-column min and max from X_train.
Args:
X_train: Training features, shape (n_train, d)
X_test: Test features, shape (n_test, d)
Returns:
Scaled X_test of shape (n_test, d), values in [0, 1] for in-distribution inputs.
"""
# YOUR CODE HERE
pass