Fitting a pareto distribution with (python) Scipy

Viewed 10962

I have a data set that I know has a Pareto distribution. Can someone point me to how to fit this data set in Scipy? I got the below code to run but I have no idea what is being returned to me (a,b,c). Also, after obtaining a,b,c, how do I calculate the variance using them?

import scipy.stats as ss 
import scipy as sp

a,b,c=ss.pareto.fit(data)
4 Answers

Let's say you data is formated like this

import openturns as ot
data = [
    [2.7018013],
    [8.53280352],
    [1.15643882],
    [1.03359467],
    [1.53152735],
    [32.70434285],
    [12.60709624],
    [2.012235],
    [1.06747063],
    [1.41394096],
]
sample = ot.Sample([[v] for v in data])

You can easily fit a Pareto distribution using ParetoFactory of OpenTURNS library:

distribution = ot.ParetoFactory().build(sample)

You can of course print it:

print(distribution)
>>> Pareto(beta = 0.00317985, alpha=0.147365, gamma=1.0283)

or plot its PDF:

from openturns.viewer import View

pdf_graph = distribution.drawPDF()
pdf_graph.setTitle(str(distribution))
View(pdf_graph, add_legend=False)

Pareto distribution

More details on the ParetoFactory are provided in the documentation.

Before passing the data to build() function in OPENTURNS, make sure to convert it this way:

data = [[i] for i in data]

Because Sample() function may return an error.

FYI @Tropilio

Related