The Python fitter library is a robust tool designed to automatically determine which probability distribution best matches an experimental or empirical dataset. By fitting dozens of distributions from scipy.stats under the hood, it systematically compares goodness-of-fit to assist in exploration, pipeline modeling, and synthetic simulations.
1. Installation
Install the fitter library into your local environment using the pip package manager:
pip install fitter
2. Basic Usage
Instantiate the main Fitter object, apply optimization routines, and print out a parsed scoring dataframe via the summary() method:
from fitter import Fitter
import numpy as np
# Generate some sample data
data = np.random.randn(1000)
# Create a Fitter object
f = Fitter(data)
# Fit the data to various distributions
f.fit()
# Print the summary of the best fitting distributions
f.summary()
The summary() method displays the top candidate distributions ordered by fitness constraints along with their calculated parameter sets (shape, location, scale).
3. Specifying Target Distributions
To reduce computational overhead, pass an explicit subset array of target distributions to evaluate if the structural properties of your data bounds are already isolated:
Pythonf = Fitter(data, distributions=['norm', 'gamma', 't'])
f.fit()
f.summary()
4. Visualizing the Fit
Generate overlay visualizations tracking your empirical histogram counts against the calculated PDFs:
Pythonf.hist()
f.plot_pdf()
5. Accessing Optimal Parameters
Extract the true optimal parameters dictionary using the get_best() method:
best_params = f.get_best()
print(best_params)
scipy.stats for continuous and discrete metrics, importing extensive architectural coverage out of the box.