A Python package for making reliable predictions using calibrating priors.
Project description
fitdistcp
fitdistcp is a free Python package for fitting statistical models using calibrating priors, with the goal of making reliable predictions. The functions provided for each distribution (GEV, GEV with 1 predictor, and GPD) accept sample data x as an argument and return a dict of the relevant results, such as quantiles, cdf, pdf, and maximum likelihood parameters. Install using >pip install fitdistcp.
fitdistcp implements the method developed in Reducing Reliability Bias in Assessments of Extreme Weather Risk using Calibrating Priors, S. Jewson, T. Sweeting and L. Jewson (2024): https://doi.org/10.5194/ascmo-11-1-2025.
More information and examples are available at https://www.fitdistcp.info, including the equivalent (more comprehensive) R package.
Development of this package was funded by the Lighthill Risk Network: https://lighthillrisknetwork.org.
Tests
- The cdf and pdf can be estimated for a set of data, using the ML (Maximum Likelihood) or CP (Calibrating Priors) method, and plotted.
- Reliability tests are provided. A reliability test involves generating a sample from a known distribution, and calculating the quantiles using the ML, or CP method. The actual quantiles can be plotted against the estimated quantiles, in various different ways, to judge the reliability of the method.
Example: Fitting a GEV distribution
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
import fitdistcp.genextreme
x = scipy.stats.genextreme.rvs(0, size=20) # make some example training data
p = np.arange(0.001,0.999,0.001) # define the probabilities at which we wish to calculate the quantiles
q = fitdistcp.genextreme.ppf(x,p) # this command calculates two sets of predictive quantiles for the GEV,
# one based on maxlik, and one that includes parameter uncertainty based on a calibrating prior
print(q['ml_params']) # have a look at the maxlik parameters
plt.plot(q['ml_quantiles'],p, label='ML') # plot the maxlik quantiles
plt.plot(q['cp_quantiles'],p,color='red', label='CP') # plot the quantiles that include parameter uncertainty
plt.legend()
plt.show()
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fitdistcp-0.0.1.tar.gz.
File metadata
- Download URL: fitdistcp-0.0.1.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca5e6e98d9ab05291522c2e068663d0e6110b9054900abd444f66653e4d26c7a
|
|
| MD5 |
1e7566b223f19326871226fc7519627e
|
|
| BLAKE2b-256 |
96c31fe8aa238226861938b474437d3c5443ce3d3f3184c7aeb386dda6a70b47
|
File details
Details for the file fitdistcp-0.0.1-py3-none-any.whl.
File metadata
- Download URL: fitdistcp-0.0.1-py3-none-any.whl
- Upload date:
- Size: 84.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84a2fee6fb2a94e07ced5253fa5cf1ce5c2a06a5d64f5d3dc33bdd4b4ba86a44
|
|
| MD5 |
88e165725c62191cdc62227f56a0fcfe
|
|
| BLAKE2b-256 |
7a377d15c7031f20f5058c7973eb5b4aa7cd3e0cc87b980301516a8fa0f965f8
|