Four Numbers, Same Misses

Machine Learning in CodeEasy+10 XP+10

Four Numbers, Same Misses

A delivery app predicted how many minutes some orders would take (guess). You also know how long they really took (truth).

Write error_report(truth, guess). Return a dict with four entries:

  • "mae": the mean absolute error.
  • "mse": the mean squared error.
  • "rmse": the square root of the mean squared error.
  • "r2": the R² score.

Use the functions from sklearn.metrics, with truth first. Round every value to 3 decimal places and return plain Python floats.

Examples

truth = [10.0, 12.0, 14.0, 16.0]
guess = [11.0, 11.0, 15.0, 20.0]
returns {'mae': 1.75, 'mse': 4.75, 'rmse': 2.179, 'r2': 0.05}
truth = [25, 30, 35, 40, 45]
guess = [27, 29, 36, 38, 47]
returns {'mae': 1.6, 'mse': 2.8, 'rmse': 1.673, 'r2': 0.944}

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