Skip to content

Commit 0f6cddd

Browse files
committed
fix: extend zero_division to percentage metrics
Add zero_division to ape, mape, sape, smape, wmape, ope, arre, marre, and coefficient_of_variation. Share denominator handling with scaled metrics while preserving their near-zero behavior. Percentage and range metrics use exact zeros: 0/0 returns 0.0, nonzero/0 returns NaN, and raise keeps explicit failure behavior. Handle zero ranges element-wise, allow negative OPE sums, and keep missing-only WMAPE and OPE inputs as NaN.
1 parent 0996a2f commit 0f6cddd

4 files changed

Lines changed: 445 additions & 91 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ but cannot always guarantee backwards compatibility. Changes that may **break co
2020
- 🔴 Improved `TransformerModel` with proper encoder-decoder transformer architecture using teacher forcing during training and autoregressive inference, aligning the implementation with [Vaswani et al., 2017](https://arxiv.org/abs/1706.03762). Previously trained checkpoints are incompatible and must be retrained. [#1915](https://github.com/unit8co/darts/pull/1915) by [Jan Fidor](https://github.com/JanFidor) and [Dennis Bader](https://github.com/dennisbader).
2121
- Added a `CITATION.cff` file with the recommended citation metadata for Darts. [#3147](https://github.com/unit8co/darts/pull/3147) by [Zhihao Dai](https://github.com/daidahao).
2222
- Added `MultivariateModel` that adds multivariate forecasting support to any base local `ForecastingModel` by fitting one model per component. This is bypassed if the base model already supports multivariate forecasting. [#1917](https://github.com/unit8co/darts/pull/1917) by [Jan Fidor](https://github.com/JanFidor) and [Dennis Bader](https://github.com/dennisbader).
23+
- 🔴 Percentage and range-based metrics (`ape`, `mape`, `sape`, `smape`, `wmape`, `ope`, `arre`, `marre`, `coefficient_of_variation`) now expose a `zero_division` parameter (mirroring [#3059](https://github.com/unit8co/darts/pull/3059)) that controls the behavior when the denominator is exactly zero. `"warn"` (default) emits a warning and uses `0.0` when the numerator is also zero or `np.nan` otherwise; `"raise"` raises a `ValueError`. For `ape`/`mape`, this replaces the previous unconditional `ValueError` on a zero in `actual_series`. [#3122](https://github.com/unit8co/darts/pull/3122) by [Mahimn](https://github.com/mahimn01).
2324

2425
**Fixed**
2526

2627
- Fixed an issue where calling `TorchForecastingModel.fit()` (for models that do not actually have to be trained) required input series to also cover the `output_chunk_length` time frame, even though the model never trains on future targets in that mode. Now input series only need to satisfy the prediction/inference input chunk length requirements. This affects all foundation models without fine-tuning, as well as global naive models. [#3154](https://github.com/unit8co/darts/pull/3154) by [Dennis Bader](https://github.com/dennisbader).
2728
- Fixed a bug in the `TorchForecastingModel.predict()` which emitted an invalid "different data type" warning for correct input data types after loading a model from a checkpoint. [#3158](https://github.com/unit8co/darts/pull/3158) by [Mohit Arvind Khakharia](https://github.com/Mohit-Ak).
2829
- Fixed a bug in `TimeSeries.window_transform()` where `treat_na` (`"dropna"`, scalar, `"bfill"`) did not handle NaN values introduced by functions that produce NaN even when `min_periods` is satisfied (e.g., `std` with `ddof=1` on a single value). [#3151](https://github.com/unit8co/darts/pull/3151) by [Dennis Bader](https://github.com/dennisbader).
30+
- Fixed `arre`/`marre` rejecting an entire input when any component of `actual_series` is constant; the zero-range denominator is now handled element-wise, so an exact prediction yields `0.0` and only undefined entries become `np.nan`. Also fixed `ope` to accept an `actual_series` with a strictly negative sum (the previous `sum > 0` check rejected valid inputs such as financial return series), and corrected the `wmape` docstring which inaccurately claimed it raised on zeros in `actual_series`. [#3122](https://github.com/unit8co/darts/pull/3122) by [Mahimn](https://github.com/mahimn01).
2931

3032
**Dependencies**
3133

0 commit comments

Comments
 (0)