Residual¶
yohou.metrics.conformity.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.
See Also¶
AbsoluteResidual: Symmetric variant using absolute residuals.GammaResidual: Scale-dependent 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¶
Show/Hide source
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 | |
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¶
Show/Hide source
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¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Use Conformity Scorers
Evaluation-Search
Compare Residual, AbsoluteResidual, GammaResidual, and AbsoluteGammaResidual conformity scorers with coverage/width analysis and DistanceSimilarity interaction.
-
How to Search Interval Forecaster Hyperparameters
Evaluation-Search
Tune interval forecaster parameters directly with interval metrics in GridSearchCV, including mixed point+interval multimetric search.
-
Conformal Prediction Intervals
Getting-Started
Build distribution-free prediction intervals with SplitConformalForecaster using calibration holdouts and configurable conformity scoring functions.