|
26 | 26 | msis, |
27 | 27 | quantile_loss, |
28 | 28 | smape, |
| 29 | + overlay_dx, |
29 | 30 | ) |
30 | 31 |
|
31 | 32 | ZEROES = np.array([0.0] * 5) |
@@ -202,3 +203,53 @@ def test_seasonal_error(past_data, seasonality, expected): |
202 | 203 | ), |
203 | 204 | expected, |
204 | 205 | ) |
| 206 | + |
| 207 | + |
| 208 | +class TestOverlayDx: |
| 209 | + """Tests for overlay_dx metric.""" |
| 210 | + |
| 211 | + def test_perfect_forecast(self): |
| 212 | + target = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) |
| 213 | + forecast = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) |
| 214 | + result = overlay_dx(target, forecast) |
| 215 | + np.testing.assert_almost_equal(result, 1.0) |
| 216 | + |
| 217 | + def test_constant_target_returns_zero(self): |
| 218 | + target = np.array([5.0, 5.0, 5.0, 5.0]) |
| 219 | + forecast = np.array([4.0, 5.0, 6.0, 7.0]) |
| 220 | + result = overlay_dx(target, forecast) |
| 221 | + np.testing.assert_almost_equal(result, 0.0) |
| 222 | + |
| 223 | + def test_score_in_unit_interval(self): |
| 224 | + rng = np.random.default_rng(42) |
| 225 | + target = rng.standard_normal(100) |
| 226 | + forecast = target + rng.standard_normal(100) * 0.5 |
| 227 | + result = overlay_dx(target, forecast) |
| 228 | + assert 0.0 <= result <= 1.0 |
| 229 | + |
| 230 | + def test_better_forecast_scores_higher(self): |
| 231 | + target = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) |
| 232 | + good_forecast = target + 0.1 |
| 233 | + bad_forecast = target + 2.0 |
| 234 | + score_good = overlay_dx(target, good_forecast) |
| 235 | + score_bad = overlay_dx(target, bad_forecast) |
| 236 | + assert score_good > score_bad |
| 237 | + |
| 238 | + def test_custom_parameters(self): |
| 239 | + target = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) |
| 240 | + forecast = np.array([0.1, 1.1, 2.1, 3.1, 4.1]) |
| 241 | + result = overlay_dx( |
| 242 | + target, forecast, |
| 243 | + max_percentage=50.0, |
| 244 | + min_percentage=1.0, |
| 245 | + step=0.5, |
| 246 | + ) |
| 247 | + assert 0.0 <= result <= 1.0 |
| 248 | + |
| 249 | + def test_symmetric(self): |
| 250 | + target = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) |
| 251 | + forecast_above = target + 0.5 |
| 252 | + forecast_below = target - 0.5 |
| 253 | + score_above = overlay_dx(target, forecast_above) |
| 254 | + score_below = overlay_dx(target, forecast_below) |
| 255 | + np.testing.assert_almost_equal(score_above, score_below) |
0 commit comments