A delivery app shows every customer a predicted arrival time. After a day of deliveries, predicted[i] and actual[i] hold the predicted and real delivery time of order i, in minutes.
Write loss_report(predicted, actual) that returns a tuple (mse, mae, rmse, worst):
mse, the mean squared error: the average of(predicted[i] - actual[i]) ** 2;mae, the mean absolute error: the average ofabs(predicted[i] - actual[i]);rmse, the square root ofmse, back in minutes;worst, the index of the order with the largest absolute error (the smallest such index if several share it).
The three losses are floats.
Examples
Input: predicted = [20, 35, 12, 50], actual = [22, 30, 12, 41]
Output: (27.5, 4.0, 5.244044240850758, 3)
Explanation: the errors are -2, 5, 0 and 9. Their squares add up to 4 + 25 + 0 + 81 = 110,
so the MSE is 110 / 4 = 27.5; their sizes add up to 16, so the MAE is 4.0.
Order 3, nine minutes out, is the worst.
Input: predicted = [10, 10, 10], actual = [8, 12, 10]
Output: (2.6666666666666665, 1.3333333333333333, 1.632993161855452, 0)
Constraints
1 <= len(actual) <= 10**5, and both lists have the same length- the times are whole numbers or floats between
0and1000
Goals
- Compute the mean squared error, mean absolute error and root mean squared error of predictions
- Find the prediction with the largest error
- See how squaring makes one large error dominate