How to Produce Prediction Intervals¶
This guide shows you how to wrap a point forecaster with
SplitConformalForecaster
to produce calibrated prediction intervals and evaluate their coverage.
Use this when you need uncertainty bounds around your forecasts, for
example to size safety stock or flag anomalous observations.
Prerequisites¶
- yohou installed (Installation)
- A fitted or unfitted point forecaster (Getting Started)
Try it interactively
Compare Residual, AbsoluteResidual, GammaResidual, and AbsoluteGammaResidual conformity scorers with coverage/width analysis and DistanceSimilarity interaction.
ViewOpen in marimoTune interval forecaster parameters directly with interval metrics in GridSearchCV, including mixed point+interval multimetric search.
ViewOpen in marimoAdaptive prediction intervals via similarity-weighted conformal prediction using DistanceSimilarity with configurable distance metrics and bandwidths.
ViewOpen in marimoWrap any quantile-capable sklearn estimator with IntervalReductionForecaster to produce calibrated prediction intervals across multiple horizons.
ViewOpen in marimoBuild distribution-free prediction intervals with SplitConformalForecaster using calibration holdouts and configurable conformity scoring functions.
ViewOpen in marimoCombine conformal and quantile regression intervals on panel data with per-group coverage analysis, calibration plots, and groupwise interval scoring.
ViewOpen in marimo1. Wrap a Point Forecaster¶
Pass any point forecaster to SplitConformalForecaster.
It holds out a calibration set from the training data and uses it to
compute conformity scores that size the intervals:
from sklearn.linear_model import Ridge
from yohou.point import PointReductionForecaster
from yohou.interval import SplitConformalForecaster
from yohou.datasets import fetch_electricity_demand
from yohou.model_selection import train_test_split
data = fetch_electricity_demand()
y = data.frame
y_train, y_test = train_test_split(y, test_size=48)
point_forecaster = PointReductionForecaster(estimator=Ridge())
interval_forecaster = SplitConformalForecaster(
point_forecaster=point_forecaster,
)
interval_forecaster.fit(y_train, forecasting_horizon=24, coverage_rates=[0.90])
coverage_rates is set at fit() time. Multiple rates can be requested at once
(coverage_rates=[0.80, 0.90, 0.95]).
If coverage is poor, increase calibration_size (default 100) to give the
conformal layer more residuals to learn from. Larger values improve calibration
but leave less data for fitting the point forecaster.
2. Predict Intervals¶
Call predict_interval to get a DataFrame with lower and upper
bound columns for each requested coverage rate:
y_pred = interval_forecaster.predict_interval()
# columns include: nsw__demand_lower_0.9, nsw__demand_upper_0.9, ...
The column naming pattern is {component}_lower_{rate} and
{component}_upper_{rate}. For multiple components or coverage rates,
one pair of columns is produced per combination.
3. Score Coverage and Sharpness¶
Use EmpiricalCoverage to check whether the intervals contain the true
values at the claimed rate, and IntervalScore to penalize both
miscoverage and unnecessarily wide intervals:
from yohou.metrics import EmpiricalCoverage, IntervalScore
coverage = EmpiricalCoverage()
coverage.fit(y_train)
print(coverage.score(y_test, y_pred))
sharpness = IntervalScore()
sharpness.fit(y_train)
print(sharpness.score(y_test, y_pred))
A well-calibrated forecaster has empirical coverage close to the
nominal rate (e.g., ~0.90 for a 90% interval). IntervalScore rewards
narrow intervals and penalizes observations that fall outside the bounds,
so lower is better.
See Also¶
- Combine Forecasters with Ensembles: average or envelope bounds from multiple interval forecasters with
VotingIntervalForecaster - Evaluate Forecast Accuracy: point and interval metric overview
- Visualize and Compare Model Scores: plot coverage and interval width over time
yohou.intervalAPI reference