GammaResidual¶
yohou.metrics.conformity.GammaResidual
¶
Bases: BaseConformityScorer
Gamma residual scorer using relative prediction errors.
Computes conformity scores as the signed relative error, normalised by the predicted value:
This scorer is useful when the scale of the target variable varies
over time, because the conformity scores are relative to the prediction
magnitude. The epsilon parameter prevents division by zero when
predictions are near zero.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float
|
Small constant added to the denominator to prevent division by zero. |
1e-8
|
See Also¶
AbsoluteGammaResidual: Symmetric variant using absolute relative errors.Residual: Scale-independent signed residual scorer.
Examples¶
>>> import polars as pl
>>> from datetime import date
>>> from yohou.metrics.conformity import GammaResidual
>>> scorer = GammaResidual(epsilon=1e-8).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)], "y": [10.0]})
>>> y_pred = pl.DataFrame({"time": [date(2020, 1, 3)], "y": [8.0]})
>>> scores = scorer.score(y_truth, y_pred)
>>> round(scores.drop("time").to_series().item(), 4)
0.25
Source Code¶
Show/Hide source
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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
Methods¶
__sklearn_tags__()
¶
score(y_truth, y_pred, /, **score_params)
¶
Compute gamma (relative) residual conformity scores.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
y_truth
|
DataFrame
|
True target values with "time" column. |
required |
y_pred
|
DataFrame
|
Predicted values with "time" column. |
required |
Returns¶
| Type | Description |
|---|---|
DataFrame
|
Relative conformity scores (y_truth - y_pred) / (y_pred + epsilon) with "time" column preserved. |
Source Code¶
Show/Hide source
inverse_score(y_pred, conformity_scores, coverage_rate)
¶
Construct prediction intervals from gamma conformity scores.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
y_pred
|
DataFrame
|
Point predictions. |
required |
conformity_scores
|
DataFrame
|
Conformity scores. |
required |
coverage_rate
|
float
|
required |
Returns¶
| Type | Description |
|---|---|
DataFrame
|
Prediction intervals. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Handle Outliers in a Forecasting Pipeline
Data-Features
Detect and clip outliers with OutlierThresholdHandler and OutlierPercentileHandler, then see how outliers affect conformal prediction intervals.
-
How to Use Conformity Scorers
Evaluation-Search
Compare Residual, AbsoluteResidual, GammaResidual, and AbsoluteGammaResidual conformity scorers with coverage/width analysis and DistanceSimilarity interaction.
-
Conformal Prediction Intervals
Getting-Started
Build distribution-free prediction intervals with SplitConformalForecaster using calibration holdouts and configurable conformity scoring functions.