Skip to main content

A simple and fast sklearn-compatible conformal predictions with random forests for both classification and regression tasks.

Project description

🌳 coverforest - Random Forest with Conformal Predictions

A simple and fast implementation of conformal random forests for both classification and regression tasks. coverforest extends scikit-learn's random forest implementation to provide prediction sets/intervals with guaranteed coverage using conformal prediction methods.

coverforest provides three conformal prediction methods for random forests:

  • CV+ (Cross-Validation+) [1, 2].
  • Jackknife+-after-Bootstrap [3].
  • Split Conformal [4].

The library provides two main classes: CoverForestRegressor for interval prediction and CoverForestClassifier. for set prediction. Here are quick runs of the two classes:

from coverforest import CoverForestRegressor

reg = CoverForestRegressor(n_estimators=100, method='bootstrap')  # using J+-a-Bootstrap
reg.fit(X_train, y_train)
y_pred, y_intervals = reg.predict(X_test, alpha=0.05)             # 95% coverage intervals
from coverforest import CoverForestClassifier

clf = CoverForestClassifier(n_estimators=100, method='cv')  # using CV+
clf.fit(X_train, y_train)
y_pred, y_sets = clf.predict(X_test, alpha=0.05)            # 95% coverage sets

🔧 Requirements

  • Python >=3.9
  • Scikit-learn >=1.6.0

⚡ Installation

You can install coverforest using pip:

pip install coverforest

Or install from source:

git clone https://github.com/donlapark/coverforest.git
cd coverforest
pip install .

Regularization in conformal set predictions

The classifier includes two regularization parameters $k$ and $\lambda$ that encourage smaller prediction sets [5].

clf = CoverForestClassifier(n_estimators=100, method='cv', k_init=2, lambda_init=0.1)

Automatic searching for suitable $k$ and $\lambda$ is also possible by specifying k_init="auto" and lambda_init="auto", which are the default values of CoverForestClassifier.

Performance Tips

Random forest leverages parallel computation by processing trees concurrently. Use the n_jobs parameter in fit() and predict() to control CPU usage (n_jobs=-1 uses all cores).

For prediction, conformity score calculations require a memory array of size (n_train × n_test × n_classes). To optimize performance with high n_jobs values, split large test sets into smaller batches.

See the documentation for more details and examples.

🔗 See Also

  • MAPIE: A Python package that provides scikit-learn-compatible wrappers for conformal classification and regression
  • conforest An R implementation of random forest with inductive conformal prediction.
  • clover A Python implementation of a regression forest method for conditional coverage ($P(Y \vert X =x)$) guarantee.
  • Conformal Prediction: Jupyter Notebook demonstrations of conformal prediction on various tasks, such as image classification, image segmentation, times series forecasting, and outlier detection
  • TorchCP A Python toolbox for Conformal Prediction in Deep Learning built on top of PyTorch
  • crepes A Python package that implements standard and Mondrian conformal classifiers as well as standard, normalized and Mondrian conformal regressors and predictive systems.
  • nonconformist: One of the first Python implementations of conformal prediction

📖 References

[1] Yaniv Romano, Matteo Sesia & Emmanuel J. Candès, "Classification with Valid and Adaptive Coverage", NeurIPS 2020.

[2] Rina Foygel Barber, Emmanuel J. Candès, Aaditya Ramdas & Ryan J. Tibshirani, "Predictive inference with the jackknife+", Ann. Statist. 49 (1) 486-507, 2021.

[3] Byol Kim, Chen Xu, Rina Foygel Barber, "Predictive inference is free with the jackknife+-after-bootstrap", NeurIPS 2020.

[4] Vladimir Vovk, Ilia Nouretdinov, Valery Manokhin & Alexander Gammerman, "Cross-conformal predictive distributions", 37-51, COPA 2018.

[5] Anastasios Nikolas Angelopoulos, Stephen Bates, Michael I. Jordan & Jitendra Malik, "Uncertainty Sets for Image Classifiers using Conformal Prediction", ICLR 2021.

[6] Leo Breiman, "Random Forests", Machine Learning, 45(1), 5-32, 2001.

📜 License

BSD-3-Clause license

📝 Citation

If you use coverforest in your research, please cite:

@software{coverforest2025,
  author = {Donlapark Ponnoprat},
  title = {coverforest: Fast Conformal Random Forests},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/donlapark/coverforest}
}

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

coverforest-0.0.3.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

coverforest-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

coverforest-0.0.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (645.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

coverforest-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

coverforest-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (643.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

coverforest-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

coverforest-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (655.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

coverforest-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

coverforest-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (618.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

coverforest-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

coverforest-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (620.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file coverforest-0.0.3.tar.gz.

File metadata

  • Download URL: coverforest-0.0.3.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for coverforest-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c1c68c8f90ba942b9cacea643a8cbfe8fcf74ddae4ec51dee169a665b4aa02d5
MD5 3a76b47eb171c5ad02a45aee064e2193
BLAKE2b-256 377449ff19164c98b96cad8a22f902253608c2fb25fb201d522722a6eac906ef

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5889336d4d666eff893054ee36beff304882cfd9d1a548539d485d97657647f8
MD5 0a23a438a4797d7f2382ff29e67109c2
BLAKE2b-256 ff17bef5a965976896398ed002f53d202fc2cb556fb9f6dc79cfe810794d3058

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbe569ff048d3a35ba3c647489a96e3b164cc3971670822039c6f8f1273c969a
MD5 78d39fc7297d6f1374a5a17c4cba73f3
BLAKE2b-256 9f9efa38fe17d9da10c15b814cff1f88239e85238511b0b93d34f584ce21a009

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 31140d376f5912896d528e0f87efe0a653a96cfe9191d7c7a60b39dd3233aa76
MD5 18bba61d5d803080254de1d243506292
BLAKE2b-256 1f822f5f6460e04e25f81da438fd6a4d7f3247605627981af8e9f70476693a10

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 723bc4b4727de27e030b09a6702b50af591acdea714f94c0a906b1074588b42e
MD5 242789588ea72f9f3420f372d9502a6e
BLAKE2b-256 d6b1abfc6a06e7d8839dffa530f9f6d03f271674caf277601ed82bef93c0531a

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 01a2f793ecd9afa374377f9d418a6908a347755ff7b9e9e815ce05c2b0ec75d1
MD5 862c580808035cd3838d06b266e29de8
BLAKE2b-256 935d1c07419ab32a476afcd2cfdc4ca5c2e526fd0e9883c6be72d2be47e7c8c5

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 de640a2d8308c6c95ec62daac57b250d9bdfa10b1e6b7371e7b795c33a977eb6
MD5 30f1fa8cc0442f68bcb1cd8481e479ac
BLAKE2b-256 329bee52212068c32c01eaaf5714285c1824afcd3618ec332d1ec6e7a0462f2e

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 117cb4306c0e230e2d43785c24f89a2d2be6f74960cf48dac24dbff9ae64ee18
MD5 4e902e906d066257c104352be2f2fc78
BLAKE2b-256 1ef02544baf5cc89937cf7b255ab6577f70ea6e2a55681f8f4b5a1a0d2669ee6

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ce7a90fc975084882a63879111d209648e88308839656070139cf0ada0e6712
MD5 25b210de952479bc8b5f86574806eeef
BLAKE2b-256 0c1477dca1baed19075cf28e2efeb49793b6e14c80881467a2502afff33f7601

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd3d1cc1dcd8d6ae572ff3d63c23726f1b89ff4efed3564a03aebf2b2fae7744
MD5 3f02cedbd20a1481e785fcbf59697a9a
BLAKE2b-256 3c6fc09d389b60728da1e82875c79dae90a9f9d7d2a48e16fff510a2236cf8f0

See more details on using hashes here.

File details

Details for the file coverforest-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for coverforest-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 14c4485f328b356170557e2b4ad3104d4884414022219eec6a8bb28f33354b84
MD5 2043306f7a046bfea93ba9005b42ad15
BLAKE2b-256 30592425157b4b11f4436b48ab8785bbf3954a920eb564984ac1f28e816edd3c

See more details on using hashes here.

Supported by

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