MedianAbsoluteError¶
yohou.metrics.MedianAbsoluteError
¶
Bases: BasePointScorer
Median Absolute Error metric for point forecasts.
Computes the median of absolute differences between predictions and actual values. This metric is highly robust to outliers and provides a more stable measure of typical error magnitude compared to mean-based metrics.
The MedianAE is defined as:
where \(y_i\) is the actual value and \(\\hat{y}_i\) is the predicted value.
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
|
time_weighter
|
BaseWeighter or None
|
Weighter applied along the time axis (observed timestamps). Because the median is non-linear, only zero-weight timestamps are dropped; non-zero weights do not otherwise reweight the median. If None, all timestamps contribute equally. |
None
|
step_weighter
|
BaseWeighter or None
|
Weighter applied along the forecasting-step axis. Only zero-weight steps
are dropped (see |
None
|
vintage_weighter
|
BaseWeighter or None
|
Weighter applied along the vintage-time axis. If None, all vintages contribute equally. |
None
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for MedianAE. |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import MedianAbsoluteError
>>> 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],
... })
>>> medae = MedianAbsoluteError()
>>> _ = medae.fit(y_true)
>>> medae.score(y_true, y_pred)
2.0
Notes ¶
- MedianAE is highly robust to outliers and extreme errors
- Provides a better measure of typical error when error distribution is skewed
- Less sensitive to a few very large prediction errors compared to MAE
- Interpretable in the same units as the target variable
- Suitable when outliers should not dominate the evaluation
See Also ¶
MeanAbsoluteError: Mean-based absolute error, more sensitive to outliersMaxAbsoluteError: Maximum absolute error, worst-case measure
Source Code ¶
Source code in src/yohou/metrics/point.py
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 | |
Methods ¶
score(y_truth, y_pred, /, **params)
¶
Compute median absolute error.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_truth
|
DataFrame
|
True values with "time" column. |
required |
y_pred
|
DataFrame
|
Predicted values with "time" column. |
required |
**params
|
dict
|
Metadata to route to nested estimators. |
{}
|
Returns ¶
| Type | Description |
|---|---|
float or DataFrame
|
Aggregated median absolute error. |
Source Code ¶
Source code in src/yohou/metrics/point.py
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 | |
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.