Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fitting a pareto distribution with (python) Scipy

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)
like image 406
alex Avatar asked Jul 13 '10 23:07

alex


People also ask

How do you create a Pareto distribution in Python?

By adding 1 and multiplying by the scale parameter x_m, classical Pareto distribution can be obtained from Lomax distribution.

What is PPF in Scipy stats?

ppf: percent point function (or inverse cumulative distribution function) ppf returns the value x of the variable that has a given cumulative distribution probability (cdf). Thus, given the cdf(x) of a x value, ppf returns the value x itself, therefore, operating as the inverse of cdf.

What does Scipy fit return?

Return estimates of shape (if applicable), location, and scale parameters from data.


1 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.

like image 52
Jean A. Avatar answered Sep 20 '22 06:09

Jean A.