Home

Awesome

Conformal-eval

A Python library for simplifying the evaluation of conformal predictors.

Installation

Installation of Conformal-eval is made by;

pip install conformal-eval

or including the extras report:

pip install conformal-eval[report]
# or, depending on your shell you might need:
pip install "conformal-eval[report]"

Examples

Examples of using the package can be seen in our examples notebooks:

Package dependencies

Package dependencies can be found in the pyproject.toml under [tool.poetry.dependencies], noting that the Jinja2 package is only required for for the report extras (installing conformal-eval[report]).

API

Data format

The code internally use numpy ndarrays for matrices and vectors, but tries to be agnostic about input being either list, arrays or Pandas equivalents. For performance reasons it is recommended that conversion to numpy format is done when using several of the methods in this library, as this is internally made in most functions.

For regression we require predictions to be the same as used in nonconformist, using 2D or 3D tensors in numpy ndarrays of shape (num_examples,2) or (num_examples,2,num_significance_levels), where the second dimension contains the lower and upper limits of the prediction intervals.

Rendering backend

Plotting is made based on the matplotlib library and Seaborn for the function plot_confusion_matrix_heatmap. To easily set a nicer plotting style (in our opinion) you can use the function conf_eval.plot.update_plot_settings which uses Seaborn to configure the default settings in matplotlib and e.g. easily scales font size.

The conf_eval.cpsign module

This module and submodules are intended for easily loading results from CPSign in the format required by Conformal-eval

Extras report

This extras include the functionality to generate a "report" in HTML format for a model generated by CPSign. This report is at this point only in beta testing and contains rudimentary information - this could be altered in the future. Further note that this will install a CLI script called cpsign-report once installing the conformal-eval[report] package, to see the usage of this simply run cpsign-report --help in your terminal environment.

Supported plots

Classification

Regression

Developer notes

Testing

All python-tests are located in the tests folder and are meant to be run using pytest. Test should be started from standing in the python folder and can be run "all at once" (python -m pytest), "per file" (python -m pytest tests/conf_eval/metrics/clf_metrics_test.py), or a single test function (python -m pytest tests/conf_eval/metrics/clf_metrics_test.py::TestConfusionMatrix::test_with_custom_labels).

Before running:

For the report module there are CLI tests that require the package to be installed before running them (otherwise the cpsign-report program is not available, or not updated). To do this you should use the following;

# Set up an venv to run in
poetry shell
# Install dependencies from the pyproject.toml
poetry install
# Run all (or subset) of tests
python -m pytest

TODOs:

Add/finish the following plots:

Change log: