Score a forecast with the three error metrics most often used for demand and business series, handling the zero cases each one has.
Implement forecast_metrics(y_true, y_pred, y_train, m=1) for arrays y_true, y_pred of equal length n≥1 and an in-sample history y_train. Let et=yt−y^t.
- MAPE =∣P∣100∑t∈P∣yt∣∣et∣, where P is the set of points with yt=0. If P is empty, MAPE is
None.
- sMAPE =n100∑t∣yt∣+∣y^t∣2∣et∣, where a term with ∣yt∣+∣y^t∣=0 counts as 0.
- MASE =N−m1∑i=mN−1∣yitrain−yi−mtrain∣n1∑t∣et∣, the forecast's mean absolute error divided by the in-sample mean absolute error of the seasonal-naive forecast with season
m (N = length of y_train). If N≤m or the denominator is 0, MASE is None.
Return a dict {"mape": ..., "smape": ..., "mase": ...} with floats rounded to 4 decimals (or None).