2010-07-13 2 views
7

파레토 분포를 가진 데이터 집합이 있습니다. 누군가가이 데이터 세트를 Scipy에 맞추는 방법을 가르쳐 줄 수 있습니까? 나는 아래의 코드를 실행해야하지만 나는 무엇이 나에게 되돌려지고 있는지 전혀 모른다 (a, b, c). 또한, a, b, c를 얻은 후에 어떻게 그것들을 사용하여 분산을 계산합니까?(python) Scipy를 사용하여 파레토 분포 맞추기

import scipy.stats as ss 
import scipy as sp 

a,b,c=ss.pareto.fit(data) 

답변

1

힘에 관한 법을 잘 살펴보십시오!보고 된 많은 전력 법칙은 사실상 강압 법칙에 적합하지 않습니다. 모든 세부 정보는 Clauset et al.을 참조하십시오 (저널에 액세스 할 수없는 경우 arxiv에도 있음). 그들은 companion website이라는 글을 파이썬 구현에 연결합니다. 마지막으로 사용했을 때 R 구현을 사용했기 때문에 Scipy를 사용하는지 알 수 없습니다.

+1

python 구현 (http://code.google.com/p/agpy/wiki/PowerLaw)에는 두 가지 버전이 있습니다. 하나는 numpy에 의존하고, 하나는 그렇지 않습니다. (내가 썼어) – keflavich

3

다음은 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) 
관련 문제