Skip to main content

A framework for calibration evaluation of binary classification models

Project description

A framework for calibration evaluation of binary classification models.


When performing classification tasks you sometimes want to obtain the probability of a class label instead of the class label itself. For example, it might be interesting to determine the risk of cancer for a patient. It is desireable to have a calibrated model which delivers predicted probabilities very close to the actual class membership probabilities. For this reason, this framework was developed allowing users to measure the calibration of binary classification models.

  • Evaluate the calibration of binary classification models with probabilistic output (LogisticRegression, SVM, NeuronalNets ...).
  • Apply your model to testdata and use true class labels and predicted probabilities as input for the framework.
  • Various statistical tests, metrics and plots are available.
  • Supports creating a calibration report in pdf-format for your model.




See the documentation for detailed information about classes and methods.

Installation

$ pip install pycaleva

or get source code directly from: https://github.com/MartinWeigl/pycaleva

Requirements

  • numpy>=1.17
  • scipy>=1.3
  • matplotlib>=3.1
  • tqdm>=4.40
  • pandas>=1.3.0
  • statsmodels>=0.13.1
  • fpdf2>=2.5.0
  • ipython>=7.30.1

Usage

  • Import and initialize
    from pycaleva import CalibrationEvaluator
    ce = CalibrationEvaluator(y_test, pred_prob, outsample=True, n_groups='auto')
    
  • Apply statistical tests
    ce.hosmerlemeshow()     # Hosmer Lemeshow Test
    ce.pigeonheyse()        # Pigeon Heyse Test
    ce.z_test()             # Spiegelhalter z-Test
    ce.calbelt(plot=False)  # Calibrationi Belt (Test only)
    
  • Show calibration plot
    ce.calibration_plot()
    
  • Show calibration belt
    ce.calbelt(plot=True)
    
  • Get various metrics
    ce.metrics()
    
  • Create pdf calibration report
    ce.calibration_report('report.pdf', 'my_model')
    

See the documentation of single methods for detailed usage examples.

Features

  • Statistical tests for binary model calibration
    • Hosmer Lemeshow Test
    • Pigeon Heyse Test
    • Spiegelhalter z-test
    • Calibration belt
  • Graphical represantions showing calibration of binary models
    • Calibration plot
    • Calibration belt
  • Various Metrics
    • Scaled Brier Score
    • Adaptive Calibration Error
    • Maximum Calibration Error
    • Area within LOWESS Curve
    • (AUROC)

The above features are explained in more detail in PyCalEva's documentation

References

  • Statistical tests and metrics:

    [1] Hosmer Jr, David W., Stanley Lemeshow, and Rodney X. Sturdivant. Applied logistic regression. Vol. 398. John Wiley & Sons, 2013.

    [2] Pigeon, Joseph G., and Joseph F. Heyse. An improved goodness of fit statistic for probability prediction models. Biometrical Journal: Journal of Mathematical Methods in Biosciences 41.1 (1999): 71-82.

    [3] Spiegelhalter, D. J. (1986). Probabilistic prediction in patient management and clinical trials. Statistics in medicine, 5(5), 421-433.

    [4] Huang, Y., Li, W., Macheret, F., Gabriel, R. A., & Ohno-Machado, L. (2020). A tutorial on calibration measurements and calibration models for clinical prediction models. Journal of the American Medical Informatics Association, 27(4), 621-633.

  • Calibration plot:

    [5] Jr, F. E. H. (2021). rms: Regression modeling strategies (R package version 6.2-0) [Computer software]. The Comprehensive R Archive Network. Available from https://CRAN.R-project.org/package=rms

  • Calibration belt:

    [6] Nattino, G., Finazzi, S., & Bertolini, G. (2014). A new calibration test and a reappraisal of the calibration belt for the assessment of prediction models based on dichotomous outcomes. Statistics in medicine, 33(14), 2390-2407.

    [7] Bulgarelli, L. (2021). calibrattion-belt: Assessment of calibration in binomial prediction models [Computer software]. Available from https://github.com/fabiankueppers/calibration-framework

    [8] Nattino, G., Finazzi, S., Bertolini, G., Rossi, C., & Carrara, G. (2017). givitiR: The giviti calibration test and belt (R package version 1.3) [Computer software]. The Comprehensive R Archive Network. Available from https://CRAN.R-project.org/package=givitiR

  • Others:

    [9] Sturges, H. A. (1926). The choice of a class interval. Journal of the american statistical association, 21(153), 65-66.

For most of the implemented methods in this software you can find references in the documentation as well.

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

pycaleva-0.2.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

pycaleva-0.2.0-py3.10.egg (47.6 kB view details)

Uploaded Source

pycaleva-0.2.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file pycaleva-0.2.0.tar.gz.

File metadata

  • Download URL: pycaleva-0.2.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for pycaleva-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8b4810d6557bc02146b5ad60b5c2980fef9b2235f3515173575bdaa03da2ef32
MD5 6c6ca8ea8c2ce37e4dfbf72431653dfd
BLAKE2b-256 fc787309258df15882420aa689f1485c66d20400d1ba0fec286ede9014ed344a

See more details on using hashes here.

File details

Details for the file pycaleva-0.2.0-py3.10.egg.

File metadata

  • Download URL: pycaleva-0.2.0-py3.10.egg
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for pycaleva-0.2.0-py3.10.egg
Algorithm Hash digest
SHA256 f282bedb42968fbd69141903ddf5dfd0b5b46519c294d79bdce03637401deb2f
MD5 033d25b87e72ebc3e3971dd5ce149307
BLAKE2b-256 52db86b7551f36f0e591d7ac4f1999118f60bf37eac13bf4b0627596a0f1f9a7

See more details on using hashes here.

File details

Details for the file pycaleva-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pycaleva-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for pycaleva-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c59b207327d4a073e8bc18a71bb2bd4bf449b61b1ce7776ebca9b820fa17836d
MD5 5dea6f1082bd2388b6e6dc2f3fb83f35
BLAKE2b-256 519914bdd770ec9d56867a1ab097032483d64a52f010fc67f993120155baabe9

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