Back to Practice
#0138

Min-Max Scale Train and Test

MediumML25 min20 XP

Problem

Given train and test lists, scale both using train min and train max. If train range is zero, use range 1.

Why This Matters

This reinforces one of the most important ML habits: never fit preprocessing on test data.

Function Signature

def minmax_train_test(train, test):

Examples

Example 1
Inputtrain=[10,20,30], test=[40]
Outputtrain=[0,0.5,1], test=[1.5]

The test value is scaled using train min 10 and max 30.

Constraints

  • Return the exact requested structure.
  • Handle normal edge cases cleanly.
  • Prefer readable code over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputtrain=[10,20,30], test=[40]
Expectedtrain=[0,0.5,1], test=[1.5]

The test value is scaled using train min 10 and max 30.

Hidden Test Categories
constant trainnegative valuestest below train min