MeanAbsoluteError¶
yohou.metrics.MeanAbsoluteError
¶
Bases: BasePointScorer
Mean Absolute Error metric for point forecasts.
Computes the average of absolute differences between predictions and actual values. This metric is robust to outliers and provides intuitive interpretation in the original units of the target variable.
The MAE is defined as:
where \(y_i\) is the actual value, \(\\hat{y}_i\) is the predicted value, and \(n\) is the number of observations.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
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 MAE. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import MeanAbsoluteError
>>> 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],
... })
>>> mae = MeanAbsoluteError()
>>> _ = mae.fit(y_true)
>>> mae.score(y_true, y_pred)
1.666...
Notes ¶
- MAE treats all errors equally regardless of direction (over or under prediction)
- Less sensitive to outliers compared to MSE/RMSE
- Interpretable in the same units as the target variable
- Suitable for most forecasting tasks where outliers should not dominate
See Also ¶
MeanSquaredError: Mean Squared Error, more sensitive to large errorsRootMeanSquaredError: Root Mean Squared Error, MeanSquaredError in original unitsRootMeanSquaredScaledError: Root Mean Squared Scaled Error, scale-independent versionMeanAbsolutePercentageError: Mean Absolute Percentage Error, scale-independent
Source Code ¶
Source code in src/yohou/metrics/point.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
Tutorials¶
The following example notebooks use this component:
-
How to Aggregate Scorer Results
Demonstrate all scorer aggregation strategies (stepwise, vintagewise, componentwise, groupwise, coveragewise, all) on panel data with weighted group aggregation.
-
How to Choose a Decomposition Strategy
Build 2- and 3-component DecompositionPipeline forecasters chaining trend, seasonality, and residual models with target pre-transformation.
-
How to Choose a Forecasting Method
Interactive decision guide progressing from SeasonalNaive baseline through linear reduction, stationarity transforms, feature enrichment, nonlinear models, decomposition, and prediction intervals.
-
How to Create a Custom Estimator
Implement a LastValueForecaster from scratch, validate it with the check generator, and use it in a forecast pipeline.
-
How to Forecast Panel Data with ColumnForecaster
Apply a shared forecasting model across multiple series in a panel dataset using ColumnForecaster with the __ column separator convention.
-
How to Forecast with CatBoost
Plug CatBoostRegressor into PointReductionForecaster as a drop-in sklearn estimator, compare gradient-boosted versus Ridge linear baseline, and demonstrate the direct reduction strategy with tree-based models.