Home

Awesome

Split Conformal Prediction and Non-Exchangeable Data

This repository contains the code for the paper Split Conformal Prediction and Non-Exchangeable Data.

Setup

Structure

Usage example

We give below a simple example of how the code in this repository can be used for data generation, conformal prediction and coverage evaluation.

from src.models import ConformalQR, RandomForestQR
from src.utils.data import get_synthetic
from src.utils.eval import empirical_coverage

# Generate data from a nonexchangeable autoregressive process
data = get_synthetic("ar1", N=1500, lags=10, seed=0, phi=0.8)

# Split the data into features and target
X, y = data.drop("target", axis=1), data["target"]

# Partition into training, calibration and test sets
X_train, y_train = X[:500], y[:500]
X_cal, y_cal = X[500:1000], y[500:1000]
X_test, y_test = X[1000:], y[1000:]

# Fit, calibrate and generate prediction intervals for a prescribed coverage level of 90%
cqr = ConformalQR(Model=RandomForestQR, alpha=0.1, seed=0)
cqr.fit(X_train, y_train)
cqr.calibrate(X_cal, y_cal)
y_pred_lower, y_pred_upper = cqr.predict(X_test)

# Evaluate coverage
empirical_coverage(y_test, y_pred_lower, y_pred_upper)

Generate figures and tables

Figures 1 and 4

Download and process climate data

Figure 2

Figure 3

Table 1

Figure 5

Figure 6

Download and process financial data

Figure 7

Table 2