【问题标题】:IndexError: only integers, slices (`:`), ellipsis (`...`) . .IndexError:只有整数、切片(`:`)、省略号(`...`)。 .
【发布时间】:2016-07-26 14:26:06
【问题描述】:

我正在使用 pymc3 来寻找最适合 3D 表面的方法。这是我正在使用的代码。

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                                                                                  

我在这一行遇到错误:

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

错误是:

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

我曾尝试通过将 sin(x) 和 cos(y) 更改为 np.sin(x) 和 np.cos(y) 来修复它,但这不起作用,我不知道还有什么去做。

【问题讨论】:

    标签: python pymc3 best-fit-curve


    【解决方案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 示例了解其他详细信息。

    【讨论】:

    • 谢谢!这对我有帮助! @aloctavodia
    猜你喜欢
    • 2019-06-25
    • 2021-04-16
    • 2017-12-25
    • 1970-01-01
    • 2017-12-08
    • 2019-03-13
    • 2017-11-24
    • 2019-12-12
    • 1970-01-01
    相关资源
    最近更新 更多