Skip to main content

A scikit-learn-compatible module for estimating prediction intervals.

Project description

Travis AppVeyor Codecov CircleCI ReadTheDocs License PythonVersion PyPi Anaconda

MAPIE - Model Agnostic Prediction Interval Estimator

MAPIE allows you to easily estimate prediction intervals using your favourite sklearn-compatible regressor.

🛠 Installation

Install via pip:

pip install mapie

To install directly from the github repository :

pip install git+https://github.com/simai-ml/MAPIE

⚡️ Quickstart

Let us start with a basic regression problem. Here, we generate one-dimensional noisy data that we fit with a linear model.

import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.datasets import make_regression

regressor = LinearRegression()
X, y = make_regression(n_samples=500, n_features=1, noise=20, random_state=59)

Since MAPIE is compliant with the standard scikit-learn API, we follow the standard sequential fit and predict process like any scikit-learn regressor.

from mapie.estimators import MapieRegressor
mapie = MapieRegressor(regressor, method="jackknife_plus")
mapie.fit(X, y)
y_preds = mapie.predict(X)

MAPIE returns a np.ndarray of shape (n_samples, 3) giving the predictions, as well as the lower and upper bounds of the prediction intervals for the target quantile. The estimated prediction interval can be easily plotted as follows.

from matplotlib import pyplot as plt
from mapie.metrics import coverage_score
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(X, y, alpha=0.3)
plt.plot(X_pi, y_preds[:, 0], color='C1')
order = np.argsort(X[:, 0])
plt.fill_between(X[order].ravel(), y_preds[:, 1][order], y_preds[:, 2][order], alpha=0.3)
plt.title(
    f"Target and effective coverages: 0.9, {coverage_score(y, y_preds[:, 1], y_preds[:, 2])}"
)
plt.show()
https://github.com/simai-ml/MAPIE/raw/master/doc/images/quickstart_1.png

📘 Documentation

The documentation can be found on this link. It contains the following sections:

📝 Contributing

You are welcome to propose and contribute new ideas. We encourage you to open an issue so that we can align on the work to be done. It is generally a good idea to have a quick discussion before opening a pull request that is potentially out-of-scope. For more information on the contribution process, please go here.

🤝 Affiliations

MAPIE has been developed through a collaboration between Quantmetry, Michelin, and ENS Paris-Saclay with the financial support from Région Ile de France.

Quantmetry Michelin ENS IledeFrance

💬 Citations

MAPIE methods are based on the work by Foygel-Barber et al. (2020).

Rina Foygel Barber, Emmanuel J. Candès, Aaditya Ramdas, and Ryan J. Tibshirani. Predictive inference with the jackknife+. Ann. Statist., 49(1):486–507, 022021

📝 License

MAPIE is free and open-source software licensed under the 3-clause BSD license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MAPIE-0.1.2.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

MAPIE-0.1.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file MAPIE-0.1.2.tar.gz.

File metadata

  • Download URL: MAPIE-0.1.2.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for MAPIE-0.1.2.tar.gz
Algorithm Hash digest
SHA256 65e0859bc358ced04adbad9fa6be7db77ec63fca50f8eb372a3a55faf8c2a79a
MD5 5ae90f2d29901d59a0a980f8363d3efa
BLAKE2b-256 57a1fc642041b040515dc6062e3a7345e6488913968c6f2a18d3ffd857f937c1

See more details on using hashes here.

File details

Details for the file MAPIE-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: MAPIE-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for MAPIE-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94d4b3df92562cafa508557e48629d6ed1a08eb6813181ac168af2a2499fee2d
MD5 7836c0bbdec752621fd1953042af3c71
BLAKE2b-256 5d7dc4b9902882cd6daad9c21293d9de91a20419362133caa8d8c69b4ffc0e11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page