AbsoluteResidual¶
yohou.metrics.AbsoluteResidual
¶
Bases: Residual
Absolute residual conformity scorer using unsigned prediction errors.
Computes conformity scores as the absolute difference between true and predicted values:
The absolute residuals produce symmetric prediction intervals, where the lower and upper bounds are equidistant from the point prediction.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
groups
|
list of str, dict of str to float, or None
|
Panel group filter (list) or filter with weights (dict). If None, all panel groups are included with equal weight. |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). If None, all components are included with equal weight. |
None
|
time_weighter
|
BaseWeighter or None
|
Weighter applied along the time axis (observed timestamps). If None, all timestamps contribute equally. |
None
|
step_weighter
|
BaseWeighter or None
|
Weighter applied along the forecasting-step axis. If None, all forecasting steps contribute equally. |
None
|
vintage_weighter
|
BaseWeighter or None
|
Weighter applied along the vintage-time axis. If None, all vintages contribute equally. |
None
|
See Also ¶
Residual: Asymmetric variant using signed residuals.AbsoluteGammaResidual: Scale-independent symmetric variant.
Examples ¶
>>> import polars as pl
>>> from datetime import date
>>> from yohou.metrics.conformity import AbsoluteResidual
>>> scorer = AbsoluteResidual().fit(
... pl.DataFrame({"time": [date(2020, 1, 1), date(2020, 1, 2)], "y": [1.0, 2.0]})
... )
>>> y_truth = pl.DataFrame({"time": [date(2020, 1, 3), date(2020, 1, 4)], "y": [3.0, 5.0]})
>>> y_pred = pl.DataFrame({"time": [date(2020, 1, 3), date(2020, 1, 4)], "y": [2.5, 6.0]})
>>> scores = scorer.score(y_truth, y_pred)
>>> scores.drop("time").to_series().to_list()
[0.5, 1.0]
Source Code ¶
Source code in src/yohou/metrics/conformity.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
Methods ¶
score(y_truth, y_pred, /, **score_params)
¶
Compute absolute residual conformity scores.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_truth
|
DataFrame
|
True target values. |
required |
y_pred
|
DataFrame
|
Predicted values. |
required |
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Conformity scores (|y_truth - y_pred|) with "time" column preserved. |
Source Code ¶
Source code in src/yohou/metrics/conformity.py
inverse_score(y_pred, conformity_scores, coverage_rate)
¶
Construct symmetric prediction intervals from absolute conformity scores.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_pred
|
DataFrame
|
Point predictions, optionally with "time" column. |
required |
conformity_scores
|
DataFrame
|
Absolute conformity scores from calibration set, optionally with "time" column. |
required |
coverage_rate
|
float
|
Desired coverage probability. |
required |
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Symmetric prediction intervals. |
Source Code ¶
Source code in src/yohou/metrics/conformity.py
Tutorials¶
The following example notebooks use this component:
-
Conformal Prediction Intervals
Build distribution-free prediction intervals with SplitConformalForecaster using calibration holdouts and configurable conformity scoring functions.
-
How to Search Interval Forecaster Hyperparameters
Tune interval forecaster parameters directly with interval metrics in GridSearchCV, including mixed point+interval multimetric search.
-
How to Use Conformity Scorers
Compare Residual, AbsoluteResidual, GammaResidual, and AbsoluteGammaResidual conformity scorers with coverage/width analysis and DistanceSimilarity interaction.
-
How to Use Distance-Based Similarity for Intervals
Adaptive prediction intervals via similarity-weighted conformal prediction using DistanceSimilarity with configurable distance metrics and bandwidths.