Fix the error report for a demand forecast
Your task
An AI evaluated a demand forecasting model with R-squared alone, reported 0.91 and picked the model with the highest score. In production the forecasts were consistently off in one direction. R-squared rewards following the ups and downs, and it is blind to a steady bias. The fix reports MAE, WAPE and bias instead.
An assistant wrote forecast_error_report(actuals, preds). It is in the editor. It has a bug. Find it and fix it.
Input and output:
actuals: the units actually sold each day.preds: the forecast for each day, at the same index.- Return a list of three numbers: MAE, WAPE and bias.
Rules the tests check:
- Use only the first n days, where n is the shorter length. If n is 0, return an empty list.
- A day's error is its forecast minus its actual.
- MAE: the mean of the absolute errors.
- WAPE: the sum of the absolute errors, divided by the sum of the absolute actuals. If that sum is 0, WAPE is -1.
- Bias: the mean of the errors, with their signs. A positive bias means the model forecasts too high.
- Answers within 0.000001 of the expected values pass.
Examples
forecast_error_report(actuals: list[float], preds: list[float]) -> list[float]Example 1
Input
forecast_error_report([100, 200, 300, 400], [110, 190, 330, 370])Output
[20, 0.08, 0]Example 2
Input
forecast_error_report([50, 50], [60, 70])Output
[15, 0.3, 15]