ale*_*lex 8 python distribution scipy
我有一个我知道有Pareto分布的数据集.有人能指出我如何在Scipy中使用这个数据集吗?我得到了下面的代码来运行,但我不知道什么是返回给我(a,b,c).此外,在获得a,b,c后,如何使用它们计算方差?
import scipy.stats as ss
import scipy as sp
a,b,c=ss.pareto.fit(data)
Run Code Online (Sandbox Code Playgroud)
这是一个快速编写的版本,从 Rupert 提供的参考页面中获取了一些提示。这目前正在 scipy 和 statsmodels 中进行,并且需要具有一些固定或冻结参数的 MLE,这仅在主干版本中可用。目前还没有关于参数估计或其他结果统计的标准误差。
'''estimating pareto with 3 parameters (shape, loc, scale) with nested
minimization, MLE inside minimizing Kolmogorov-Smirnov statistic
running some examples looks good
Author: josef-pktd
'''
import numpy as np
from scipy import stats, optimize
#the following adds my frozen fit method to the distributions
#scipy trunk also has a fit method with some parameters fixed.
import scikits.statsmodels.sandbox.stats.distributions_patch
true = (0.5, 10, 1.) # try different values
shape, loc, scale = true
rvs = stats.pareto.rvs(shape, loc=loc, scale=scale, size=1000)
rvsmin = rvs.min() #for starting value to fmin
def pareto_ks(loc, rvs):
est = stats.pareto.fit_fr(rvs, 1., frozen=[np.nan, loc, np.nan])
args = (est[0], loc, est[1])
return stats.kstest(rvs,'pareto',args)[0]
locest = optimize.fmin(pareto_ks, rvsmin*0.7, (rvs,))
est = stats.pareto.fit_fr(rvs, 1., frozen=[np.nan, locest, np.nan])
args = (est[0], locest[0], est[1])
print 'estimate'
print args
print 'kstest'
print stats.kstest(rvs,'pareto',args)
print 'estimation error', args - np.array(true)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6866 次 |
| 最近记录: |