python - Getting a pdf from scipy.stats in a generic way -


i running goodness of fit tests using scipy.stats in python 2.7.10.

for distrname in distrnamelist:     distr = getattr(distributions, distrname)     param = distr.fit(sample)     pdf   = distr.pdf(???) 

what pass distr.pdf() values of best-fit pdf on list of sample points of interest, called abscissas?

to evaluate pdf @ abscissas, pass abcissas first argument pdf. specify parameters, use * operator unpack param tuple , pass values distr.pdf:

pdf = distr.pdf(abscissas, *param) 

for example,

import numpy np import scipy.stats stats  distrnamelist = ['beta', 'expon', 'gamma'] sample = stats.norm(0, 1).rvs(1000) abscissas = np.linspace(0,1, 10) distrname in distrnamelist:     distr = getattr(stats.distributions, distrname)     param = distr.fit(sample)     pdf = distr.pdf(abscissas, *param)     print(pdf) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -