我正在按照本教程使用贝叶斯统计信息来辅助A / B测试。 https://medium.com/@thibalbo/coding-bayesian-ab-tests-in-python-e89356b3f4bd我遇到以下错误
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\Anaconda3\pymc3\model.py in get_context(cls)
179 try:
--> 180 return cls.get_contexts()[-1]
181 except IndexError:
IndexError: list index out of range
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-14-55619ff3a91c> in <module>()
1 # define metrics
----> 2 pm.Deterministic('difference', prior_v2 - prior_v1)
3 pm.Deterministic('relation', (prior_v2/prior_v1) - 1)
~\Anaconda3\pymc3\model.py in Deterministic(name, var, model)
1415 var : var, with name attribute
1416 """
-> 1417 model = modelcontext(model)
1418 var.name = model.name_for(name)
1419 model.deterministics.append(var)
~\Anaconda3\pymc3\model.py in modelcontext(model)
188 """
189 if model is None:
--> 190 return Model.get_context()
191 return model
192
~\Anaconda3\pymc3\model.py in get_context(cls)
180 return cls.get_contexts()[-1]
181 except IndexError:
--> 182 raise TypeError("No context on context stack")
183
184
TypeError: No context on context stack
这是我的代码,在“定义指标”之后引发错误:
%matplotlib inline
import pymc3 as pm
import seaborn as sb
n = 1000
A = 680
B = 700
with pm.Model() as model: # context management
# define priors
prior_v1 = pm.Beta('prior_v1', alpha=2, beta=2)
prior_v2 = pm.Beta('prior_v2', alpha=2, beta=2)
# define likelihood
like_v1 = pm.Binomial('like_v1', n=n, p=prior_v1, observed=A)
like_v2 = pm.Binomial('like_v2', n=n, p=prior_v2, observed=B)
# define metrics
pm.Deterministic('difference', prior_v2 - prior_v1)
pm.Deterministic('relation', (prior_v2/prior_v1) - 1)