Min-Max Scaling: Everything Between 0 and 1

Data ProcessingEasy+10 XP+10

Min-Max Scaling: Everything Between 0 and 1

Features arrive on wildly different scales — age in years, income in tens of thousands — and any model that measures distance or shares one learning rate will quietly let the big one dominate. Min-max scaling squeezes everything onto [0, 1]:

1scaled = (value - min) / (max - min)

Task: write min_max_normalize(values) returning the scaled list, rounded to 4 decimal places.

  • The smallest value becomes exactly 0.0 and the largest exactly 1.0.
  • If every value is identical there's no range to divide by — return all zeros rather than dividing by zero.
  • An empty list returns an empty list.

This is the scaler that outliers punish hardest. One value ten times larger than the rest compresses everything else into a sliver near zero, which is the usual reason to reach for a z-score or a robust scaler instead.

weight
110170
sweetness
28
0.00.51.0one shared scale

In raw numbers weight spans 60 while sweetness spans 6. The highlighted pair sits far apart on one track and almost together on the other.

Examples

values = [2.0, 4.0, 6.0, 8.0]
returns [0.0, 0.3333, 0.6667, 1.0]
values = [-5.0, 0.0, 5.0]
returns [0.0, 0.5, 1.0]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run