SymmetricMeanAbsolutePercentageError¶
yohou.metrics.SymmetricMeanAbsolutePercentageError
¶
Bases: BasePointScorer
Symmetric Mean Absolute Percentage Error metric for point forecasts.
Computes the symmetric average percentage error between predictions and actual values. This provides a scale-independent metric that treats over and under-predictions equally, unlike MAPE which is asymmetric.
The sMAPE is defined as:
where \(y_i\) is the actual value, \(\\hat{y}_i\) is the predicted value, and \(n\) is the number of observations. Values are bounded between 0 and 200.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float
|
Small constant added to denominator to prevent division by zero when both actual and predicted values are zero or near-zero. |
1e-8
|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. Options: - "stepwise": Aggregate across forecasting steps. - "vintagewise": Aggregate across vintages (observed times). - "componentwise": Aggregate across components, return per-timestep DataFrame - "groupwise": Aggregate across panel groups (panel data only) - "all": Aggregate across all dimensions (returns scalar). Same as ["stepwise", "vintagewise", "componentwise", "groupwise"]. Example outputs: - ["stepwise", "vintagewise"]: Per-component (and per-group) DataFrame. - "componentwise" or ["componentwise"]: Per-timestep (and per-group) DataFrame. - "groupwise" or ["groupwise"]: Per-component per-timestep DataFrame (panel aggregated). - ["stepwise", "vintagewise", "componentwise"]: Scalar (global) or per-group DataFrame (panel). - "all": Scalar float (hierarchically aggregated for panel data). |
"all"
|
groups
|
list of str, dict of str to float, or None
|
Panel group filter (list) or filter with weights (dict). |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). |
None
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for sMAPE. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import SymmetricMeanAbsolutePercentageError
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [10.0, 20.0, 30.0],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 3,
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [12.0, 19.0, 28.0],
... })
>>> smape = SymmetricMeanAbsolutePercentageError()
>>> _ = smape.fit(y_true)
>>> smape.score(y_true, y_pred)
10.06...
Notes ¶
- sMAPE is symmetric: treats over-predictions and under-predictions equally
- Scale-independent and useful for comparing forecasts across different series
- Bounded between 0 and 200 (unlike MAPE which is unbounded)
- Less sensitive to very small actual values compared to MAPE
- Undefined when both actual and predicted values are zero; epsilon prevents division by zero
See Also ¶
MeanAbsolutePercentageError: Asymmetric version of percentage errorMeanAbsoluteError: Absolute error in original unitsMeanAbsoluteScaledError: Scaled by naive forecast error
Source Code ¶
Source code in src/yohou/metrics/point.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | |
Tutorials¶
The following example notebooks use this component:
-
How to Use Point Forecast Metrics
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.