Residual¶
yohou.metrics.Residual
¶
Bases: BaseConformityScorer
Residual-based conformity scorer using signed prediction errors.
Computes conformity scores as the signed difference between the true and predicted values:
The signed residuals produce asymmetric prediction intervals, where the lower and upper bounds can differ in width 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 ¶
AbsoluteResidual: Symmetric variant using absolute residuals.GammaResidual: Scale-independent variant using relative errors.SplitConformalForecaster: Conformal prediction forecaster that uses conformity scorers.
Examples ¶
>>> import polars as pl
>>> from datetime import date
>>> from yohou.metrics.conformity import Residual
>>> scorer = Residual().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, 4.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
25 26 27 28 29 30 31 32 33 34 35 36 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
Methods ¶
score(y_truth, y_pred, /, **score_params)
¶
Compute signed 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 prediction intervals from conformity scores.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_pred
|
DataFrame
|
Point predictions, optionally with "time" column. |
required |
conformity_scores
|
DataFrame
|
Computed conformity scores from calibration set, optionally with "time" column. |
required |
coverage_rate
|
float
|
Desired coverage probability (e.g., 0.9 for 90% intervals). |
required |
Returns ¶
| Type | Description |
|---|---|
DataFrame
|
Prediction intervals with lower and upper bounds, and time columns if input had them. |
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.