Google colab 存在一些与贝叶斯分析和相应库相关的问题



我正在研究 python 贝叶斯分析一书,并尝试在 python 中实现所有代码,为此我使用 google colab,但是当我运行以下书中的代码时

import arviz
import pymc3 as pm
import numpy as np
from scipy import stats
np.random.seed(123)
n_experiments=4
theta_real =0.35
data =stats.bernoulli.rvs(p=theta_real,size=n_experiments)
with pm.Model()  as our_first_model:
theta =pm.Beta('theta',alpha=1,beta=1)
y =pm.Bernoulli('y',p=theta,observed=data)
start =pm.find_MAP()
step =pm.Metropolis()
trace =pm.sample(1000,step=step,start=start)
burnin=100
chain =trace[burnin:]
pm.traceplot(chain,lines={'theta':theta_real})

它给出了这样的错误:

AttributeError: Installed version of ArviZ requires PyMC3>=3.8. Please upgrade with `pip install pymc3>=3.8` or `conda install -c conda-forge pymc3>=3.8`

在我尝试实现这些库之前

!pip install pymc3>=3.8
!pip install arviz

但仍然没有成功。如何修复此错误?

您是否尝试过重新启动会话?使用!pip install pymc3>=3.8进行升级后,您必须重新启动会话,然后执行import pymc3 as pm否则它仍将考虑以前安装的版本。

最新更新