tweedie#

scikitplot.externals._tweedie.tweedie = <scikitplot.externals._tweedie._tweedie_dist.tweedie_gen object>[source]#

An instance of tweedie_gen, providing Tweedie distribution functionality.

This instance provides:

  • probability density function (pdf)

  • cumulative distribution function (cdf)

  • random sampling

for the Tweedie distribution.

The Tweedie distribution is part of the exponential dispersion family, characterized by a p parameter that determines its behavior:

  • p = 0: Gaussian distribution

  • p = 1: Poisson distribution

  • p = 2: Gamma distribution

  • p = 3: Inverse Gaussian distribution

  • 1 < p < 2: Compound Poisson-Gamma distribution

Parameters:
pfloat

Tweedie power parameter.

mufloat

Mean or location parameter.

phifloat

Dispersion parameter, controlling the variance of the distribution.

See also

tweedie_gen

A Tweedie continuous random variable.

Examples

Compute the pdf and cdf at a given point:

>>> import numpy as np
>>> from scikitplot.stats import tweedie
>>> x = 2.0
>>> pdf_val = tweedie.pdf(x, p=1.5, mu=1, phi=1)
>>> cdf_val = tweedie.cdf(x, p=1.5, mu=1, phi=1)
>>> pdf_val, cdf_val
(np.float64(0.15640119832636348), np.float64(0.8519363569424107))

Generate random variates:

>>> import numpy as np
>>> from scikitplot.stats import tweedie
>>> rvs = tweedie.rvs(p=1.5, mu=1, phi=1, size=16)
>>> rvs
array([1.70346018, 0.81489777, 1.50314411, 0.59856305, 0.06782621,
       0.        , 2.20771566, 0.12384126, 0.90230741, 0.06957144,
       3.27144488, 0.11904818, 3.32579731, 0.        , 2.27663086,
       2.04118574])

Plot the pdf over a range:

>>> import numpy as np
>>> from scikitplot.stats import tweedie
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 5, 100)
>>> y = tweedie.pdf(x, p=1.5, mu=1, phi=1)
>>> plt.plot(x, y, label='Tweedie pdf (p=1.5, mu=1, phi=1)')
>>> plt.xlabel("x")
>>> plt.ylabel("Density")
>>> plt.legend()
>>> plt.show()

(Source code, png)

../../_images/scikitplot-externals-_tweedie-tweedie-1.png