使用 PyMC3 的指数函数时出错

Error when using PyMC3's Exponential function

为了生成指数函数的 lambda 值,我在 Python 3.7 中尝试了以下简单的 PyMC3 代码。

但我却遇到了以下错误。

你能告诉我问题是什么吗?

代码

import pymc3 as pm

lambda_1 = pm.Exponential('lambda_1', 1)


lambda_2 = pm.Exponential('lambda_2', 1)

错误

TypeError: No model on context stack, which is needed to instantiate distributions. Add variable inside a 'with model:' block, or use the '.dist' syntax for a standalone distribution.

试试这个:

import pymc3 as pm

with pm.Model() as model:
    lambda_1 = pm.Exponential('lambda_1', 1)
    lambda_1 = pm.Exponential('lambda_2', 1)

我保证它会消除你的错误! 编码愉快!