关于pymc3报错问题

import pymc3 as pm
import numpy as np
import scipy.stats as stats
import matplotlib.pyplot as plt
import seaborn as sns
palette = 'muted'
sns.set_palette(palette); sns.set_color_codes(palette)

np.random.seed(123)
n_experiments = 4
theta_real = 0.35  # unkwon value in a real experiment
data = stats.bernoulli.rvs(p=theta_real, size=n_experiments)

with pm.Model() as our_first_model:
    # a priori
    theta = pm.Beta('theta', alpha=1, beta=1)
    # likelihood
    y = pm.Bernoulli('y', p=theta, observed=data)
    #y = pm.Binomial('theta',n=n_experimentos, p=theta, observed=sum(datos))
    start = pm.find_MAP()
    step = pm.Metropolis()
    trace = pm.sample(1000, step=step, start=start,cores=1)

with our_first_model:
    step = pm.Metropolis()
    multi_trace = pm.sample(1000, step=step,cores=1)

if __name__ == '__main__':
    burnin = 0  # no burnin
    multi_chain = multi_trace[burnin:]
    pm.traceplot(multi_chain, lines={'theta':theta_real})
    plt.show()
    # print(pm.gelman_rubin(multi_chain))
    pm.forestplot(multi_chain, varnames=['theta'])
    plt.show()

总这样报错呢!?????????????????????????

TypeError                                 Traceback (most recent call last)
<ipython-input-1-88ae9a9ad243> in <module>
     34     plt.show()
     35     # print(pm.gelman_rubin(multi_chain))
---> 36     pm.forestplot(multi_chain, varnames=['theta'])
     37     plt.show()
     38 

~\anaconda3\lib\site-packages\pymc3\plots\__init__.py in wrapped(*args, **kwargs)
     37         if "varnames" in kwargs:
     38             raise DeprecationWarning(
---> 39                 f"The `varnames` kwarg was renamed to `var_names`.", stacklevel=2
     40             )
     41         original = func.__name__

TypeError: DeprecationWarning() takes no keyword arguments

源码中有一个弃用警告,就是说pymc3中的有关plot函数的关键字参数varnames已经弃用,改成了var_names,用var_names=['theta']试试。

takes no keyword arguments,不能使用关键字作为参数或变量名称。

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

速戳参与调研>>>https://t.csdnimg.cn/Kf0y