Home:ALL Converter>fit theoretical distribution and draw random values

fit theoretical distribution and draw random values

Ask Time:2022-04-02T08:29:30         Author:d.b

Json Formatter

In order to fit given data to theoretical distribution and then draw random values from that distribution, does this scheme work with all distributions in scipy.stats?

from scipy.stats import beta, expon, gamma, genpareto, genextreme, lognorm, kappa3, pearson3, weibull_min

data = [529, 7065, 2739, 1838, 817, 1376, 3791, 5070,
        736, 805, 577, 2963, 7017, 3026, 2542, 2160,
        221, 3340, 582, 1080, 1040, 1310, 5500, 4800,
        485, 7110, 4150, 2700, 4610, 1270, 10476, 1975,
        731, 150, 1163, 985, 5476, 5762, 1750, 609, 1009,
        14704, 678, 3837, 1069, 948, 460, 1819, 5958,
        1356, 2025, 1136, 4500, 882, 8230, 3521, 1561,
        695, 3380, 1210, 4311]

d = {"beta": beta,
     "expon": expon,
     "gamma": gamma,
     "genpareto": genpareto,
     "genextreme": genextreme,
     "lognorm": lognorm,
     "kappa3": kappa3,
     "pearson3": pearson3,
     "weibull_min": weibull_min} # there could be more later

ans = {}
for nm, f in d.items():
    params = f.fit(data)
    ans[nm] = f.rvs(*params, size=100)

I am mainly concerned about the ans[nm] = f.rvs(*params, size=100) line. Does *params always insert appropriate arguments into the rvs method? Or is it necessary to tinker with input based on distribution? For example, in case of pearson3, is it necessary to separately calculate skew?

Author:d.b,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71713971/fit-theoretical-distribution-and-draw-random-values
ev-br :

\nf.rvs(*params, size=100) line. Does *params always insert appropriate arguments into the rvs method?\n\nYes.\nf.fit returns a tuple of shapes, loc, scale, which can be unpacked into all other methods of f.",
2022-04-03T07:06:31
Ekansh :

Yes, as ev-br mentioned *params will insert the appropriate arguments into the rvs method.\nFrom scipy's documentation for scipy.stats.rv_continuous.fit:\nReturns a tuple of estimates for any shape parameters (if applicable), followed by those for location and scale.\nShape parameters, location, and scale can be unpacked from the params in your code\nThese estimates for shape parameters are then used by scipy.stats.rv_continuous.rvs\n",
2022-04-11T08:24:50
yy