From 0 to 1

Machine Learning in CodeEasy+10 XP+10

From 0 to 1

A weather station records temperatures. Before a model uses them, they should run from 0 to 1.

Task: write min_max(values).

  • values is a list of numbers, all from one column.
  • Scale them with scikit-learn's MinMaxScaler. The smallest value becomes 0 and the largest becomes 1.
  • Return the scaled values as a plain list, each rounded to 3 decimal places, in the original order.
  • If every value is the same, the scaler turns them all into 0.0. Just return what it gives you.

Examples

values = [110, 130, 150, 160, 170]
returns [0.0, 0.333, 0.667, 0.833, 1.0]
values = [12.5, -3.0, 4.0, 20.0]
returns [0.674, 0.0, 0.304, 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