def __init__(self, data, mleDiffCutoff=1.0):
print [min(data), max(data)]
distributions = [st.laplace, st.norm, st.expon, st.dweibull, st.invweibull, st.lognorm, st.uniform]
mles = []
for distribution in distributions:
pars = distribution.fit(data)
mle = distribution.nnlf(pars, data)
mles.append(mle)
results = [(distribution.name, mle) for distribution, mle in zip(distributions, mles)]
for dist in sorted(zip(distributions, mles), key=lambda d: d[1]):
print dist
best_fit = sorted(zip(distributions, mles), key=lambda d: d[1])[0]
print 'Best fit reached using {}, MLE value: {}'.format(best_fit[0].name, best_fit[1])
self.modelSets = []
self.modelOptions = [mod[0].name for mod in sorted(zip(distributions, mles), key=lambda d: d[1])]
## list of scipy distribution ids sorted by their MLEs given the data
## [0] is best, [1], next best and so on
for model in sorted(zip(distributions, mles), key=lambda d: d[1]):
if(model[0].name in getAvailableDistributionsByScipyIds()):
try:
modelDist = getDistributionByScipyId(model[0].name, data)
self.modelSets.append([modelDist, model[1]])
## append the distribution object and the MLE value for this
## particular distribution & the data
## ah frig, I think in the bimodal case, it will be
## something like
except RuntimeError:
pass
else:
## nothing that can be done here, if we dont have a object of
## the distribution needed available, we cant do much about it
pass
评论列表
文章目录