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. 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.
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()
Models
The following models are currently supported. Let us know if you have any suggestions for other models to include.
- expon: Exponential distribution
- gamma: Gamma distribution
- genextreme: Generalised Extreme Value (GEV) distribution
- genextreme_p1 & genextreme_p12: Generalised Extreme Value (GEV) distribution, with 1 predictor, 2 predictors
- genpareto: Generalised Pareto distribution
- gumbel: Gumbel distribution
- lnorm: Lognormal distribution
- norm: Normal distribution
- weibull: Weibull distribution
Methods
Four methods are provided for each model: ppf(x) (quantiles, 'percentage point function'), rvs(n, x) (random variates), pdf(x) and cdf(x), where x is the data to fit. To use, e.g. ppf for the normal distribution, import fitdistcp.norm and call fitdistcp.norm.ppf(x). To test the methods use e.g. fitdistcp.norm.reltest(). Reltests (reliability tests) are used to test the reliability of quantile calculations for making predictions.
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.1.0.tar.gz.
File metadata
- Download URL: fitdistcp-0.1.0.tar.gz
- Upload date:
- Size: 82.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70e42827433c196ca0b1f859ac882daa70996136fcad961a6886bd41400ff603
|
|
| MD5 |
8de3a6b62ceb144446098519e95329f7
|
|
| BLAKE2b-256 |
7dfeb15985572abed82a919ed9181ddcfa2031d03239624945be4e0620dee0e4
|
File details
Details for the file fitdistcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fitdistcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 104.1 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 |
fd8eaddb06de2fb60a91f4eb2f7ef43db0ac2f8b3307706f9da501c2b3010a62
|
|
| MD5 |
a14c85f02fb07bb62d45f93a2280a71a
|
|
| BLAKE2b-256 |
109034d1ae1a04989c564b1c2cf6007e21e98ba8d74dc5f35056ac2ec799ce9c
|