def owa( target: np.ndarray, forecast: np.ndarray, past_data: np.ndarray, seasonal_error: float, start_date: pd.Timestamp, ) -> float: r""" .. math:: owa = 0.5*(smape/smape_naive + mase/mase_naive) https://www.m4.unic.ac.cy/wp-content/uploads/2018/03/M4-Competitors-Guide.pdf """ # avoid import error due to circular dependency from gluonts.model.baseline import naive_2 # calculate the forecast of the seasonal naive predictor naive_median_fcst = naive_2(past_data, len(target), freq=start_date.freqstr) owa = 0.5 * ( (Evaluator.smape(target, forecast) / Evaluator.smape(target, naive_median_fcst)) + (Evaluator.mase(target, forecast, seasonal_error) / Evaluator.mase(target, naive_median_fcst, seasonal_error))) return owa
def test_naive_2(prediction_length=FH, season_length=FRQ): r_naive_2_inputs, r_naive_2_outputs = load_naive_2_data() predictions = [] for i in range(len(r_naive_2_inputs)): predictions.append( naive_2( r_naive_2_inputs[i], prediction_length=prediction_length, season_length=season_length, )) predictions = np.array(predictions) assert np.allclose(r_naive_2_outputs, predictions)