2016-07-26 62 views
0

나는 pymc3를 사용하여 3D 표면에 가장 잘 맞는 것을 찾습니다. 이것은 내가 사용하고있는 코드입니다.IndexError : 정수, 슬라이스 (`:`), 줄임표 (`...`) 만 있습니다. .

glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , flatimage) 

오류는 다음과 같습니다 :

with Model() as model: 
# specify glm and pass in data. The resulting linear model, its likelihood and                         
# and all its parameters are automatically added to our model.                             
glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , flatimage) 
start = find_MAP() 
step = NUTS(scaling=start) # Instantiate MCMC sampling algorithm                             
trace = sample(2000, step, progressbar=False) # draw 2000 posterior samples using NUTS sampling                     

나는이 라인에 오류가있어 내가 죄를 변경하여 그것을 해결하기 위해 노력했다

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices 

를 (x)와 COS (Y) np.sin (x)와 np.cos (y)로 변환 할 수 있지만 작동하지 않아 다른 작업을 수행 할 수 없습니다.

답변

1

나는 문제가 flatimage의 정의와 관련이 있다고 생각합니다. glm 모듈이 작동하려면 데이터가 필요합니다. 다음과 같은 내용 :

# synthetic data (just an example) 
x = np.random.normal(size=100) 
y = np.random.normal(size=100) 
z = x**2 + y**2 + x + y + np.sin(x) + np.cos(y) 

data = dict(x=x, y=y, z=z) # a pandas dataframe will also work 

with pm.Model() as model: 
    pm.glm.glm('z ~ x**2 + y**2 + x + y + np.sin(x) + np.cos(y)' , data) 
    start = pm.find_MAP() 
    step = pm.NUTS(scaling=start)   
    trace = pm.sample(2000, step, start) 

다른 세부 정보는 this 예를 확인하십시오.

+0

고맙습니다! 이것은 나를 도왔다! @aloctavodia – VD97