Conformal Regression#
Conformal Prediction (CP) は予測区間(prediction intervals)を算出するためのフレームワーク。
予測の残差から予測の幅を算出する。
DMLのcross-fittingのように、train setでは残差の予測モデルをfitせず、分けておいたcalibration setで残差の学習を行う。
前提#
問題設定#
exchangeability#
サンプル
例えばサンプルが3つあるとして、
Conformal Regression#
まず、訓練データを2つに分割する
training set:
calibration set:
任意の回帰アルゴリズム
calibration setで残差の絶対値を計算する
所与の水準
新しく与えられた点
Show code cell source
# generate data
import numpy as np
import matplotlib.pyplot as plt
n = 1000
np.random.seed(0)
x = np.random.uniform(low=0, high=1, size=n)
y = x**3 + 2 * np.exp(-6 * (x - 0.3)**2)
y = y + np.random.normal(loc=0, scale=x * 0.3, size=n)
from sklearn.model_selection import train_test_split
X = x.reshape(-1, 1)
X_train, X_cal, y_train, y_cal = train_test_split(X, y, test_size=0.33, random_state=42)
# calculate residual
from lightgbm import LGBMRegressor
model = LGBMRegressor(verbose=-1)
model.fit(X_train, y_train)
abs_residuals = np.abs(y_cal - model.predict(X_cal))
# aclculate quantile
quantile = np.quantile(abs_residuals, q=0.9)
# plot
x_range = np.linspace(x.min(), x.max(), 100)
y_pred = model.predict(x_range.reshape(-1, 1))
fig, ax = plt.subplots(figsize=[6, 3])
ax.scatter(x, y, alpha=0.3, color="gray")
ax.plot(x_range, y_pred, alpha=0.9, color="black")
ax.plot(x_range, y_pred + quantile, alpha=0.9, color="steelblue")
ax.plot(x_range, y_pred - quantile, alpha=0.9, color="steelblue")
fig.show()
/usr/local/lib/python3.10/site-packages/sklearn/utils/validation.py:2739: UserWarning: X does not have valid feature names, but LGBMRegressor was fitted with feature names
warnings.warn(
/usr/local/lib/python3.10/site-packages/sklearn/utils/validation.py:2739: UserWarning: X does not have valid feature names, but LGBMRegressor was fitted with feature names
warnings.warn(

Adaptive Conformal Prediction#
区間の幅を可変にしたものの総称?
Conformalized quantile regression#
locally adaptive
Romano et al. (2019). Conformalized quantile regression.
Seedat et al. (2023, April). Improving adaptive conformal prediction using self-supervised learning.