MAPIE (Mapping Prediction Intervals)

1.3.0 · active · verified Thu Apr 16

MAPIE (Mapping Prediction Intervals) is a scikit-learn-compatible Python library for estimating prediction intervals. It provides tools for both regression and classification tasks, leveraging conformal prediction methods to quantify uncertainty. The current version is 1.3.0, and the library maintains an active release cadence with several major and minor updates per year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `MapieRegressor` to train a model and predict prediction intervals on synthetic regression data. It uses a `LinearRegression` model as the base estimator.

import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_regression
from mapie.regression import MapieRegressor

# 1. Generate synthetic data
X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

# 2. Fit a MAPIE regressor
regressor = LinearRegression()
mapie_regressor = MapieRegressor(regressor, cv="split", random_state=42)
mapie_regressor.fit(X_train, y_train)

# 3. Predict prediction intervals
y_pred, y_pis = mapie_regressor.predict(X_test, alpha=0.1)

# 4. Print results (example)
print(f"Predicted value for first test sample: {y_pred[0]:.2f}")
print(f"Prediction interval for first test sample: [{y_pis[0, 0, 0]:.2f}, {y_pis[0, 1, 0]:.2f}]")

view raw JSON →