MeanAbsoluteScaledError¶
yohou.metrics.MeanAbsoluteScaledError
¶
Bases: BasePointScorer
Mean Absolute Scaled Error metric for point forecasts.
Computes MAE scaled by the in-sample naive seasonal forecast error. This provides a scale-independent metric that enables comparison across time series with different magnitudes. Requires training data to compute scaling factors.
The MASE is defined as:
where the scale is computed from training data as:
with \(m\) = seasonality, \(T\) = training length, \(h\) = forecast horizon, and \(j\) = column index. Per-column MASE values are averaged to produce the final score.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int
|
Seasonal period for computing scaling factors. Must be at least 1. Common values: 1 (non-seasonal), 7 (weekly), 12 (monthly), 24 (hourly daily pattern). |
1
|
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 MASE. |
naive_errors_ |
dict[str, float]
|
Fitted per-column scaling factors based on naive seasonal forecast MAE. Computed during fit() from training data. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime, timedelta
>>> from yohou.metrics import MeanAbsoluteScaledError
>>> # Training data
>>> y_train = pl.DataFrame({
... "time": [datetime(2020, 1, 1) + timedelta(days=i) for i in range(10)],
... "value": [10.0, 12.0, 11.0, 13.0, 12.0, 14.0, 13.0, 15.0, 14.0, 16.0],
... })
>>> # Test predictions
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 11), datetime(2020, 1, 12)],
... "value": [15.0, 17.0],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2020, 1, 10)] * 2,
... "time": [datetime(2020, 1, 11), datetime(2020, 1, 12)],
... "value": [15.5, 16.5],
... })
>>> mase = MeanAbsoluteScaledError(seasonality=2)
>>> mase.fit(y_train)
MeanAbsoluteScaledError(seasonality=2)
>>> mase.score(y_true, y_pred)
0.5...
Notes ¶
- MASE values are scale-independent, enabling comparison across different time series
- Values < 1 indicate better performance than naive seasonal forecast on training data
- Values > 1 indicate worse performance than naive seasonal baseline
- Requires training data with length > seasonality
- Per-column scaling factors are stored and applied independently
- More interpretable than RMSSE as it uses absolute errors rather than squared errors
See Also ¶
RootMeanSquaredScaledError: Squared error version of scaled metricMeanAbsoluteError: Non-scaled MAEMeanAbsolutePercentageError: Percentage-based scale-independent metric
Source Code ¶
Source code in src/yohou/metrics/point.py
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
Methods ¶
__sklearn_tags__()
¶
fit(y_train, *, forecaster=None, **params)
¶
Fit the scorer by computing per-column scaling factors.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_train
|
DataFrame
|
Training set target values with "time" column. |
required |
forecaster
|
BaseForecaster or None
|
If provided, metadata is extracted directly from the fitted
forecaster instead of being re-inferred from |
None
|
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
self
|
|
Raises ¶
| Type | Description |
|---|---|
ValueError
|
If y_train is None or seasonality > len(y_train) - 1. |
Warns:
| Type | Description |
|---|---|
UserWarning
|
If any training column has zero variance for the given seasonality; a scale floor of 1e-10 is used instead. |
Source Code ¶
Source code in src/yohou/metrics/point.py
Tutorials¶
The following example notebooks use this component:
-
Forecasting Workflow
Evaluate forecasters with cross-validation, search hyperparameters with GridSearchCV, and inspect residuals to diagnose model weaknesses.
-
How to Use Point Forecast Metrics
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.
-
Observe-Predict Workflow
Walk through a test set in batches, updating forecasts as new data arrives with observe_predict.