Getting started with PYMC for linear regression

Thought I'd start with this example: http://www.databozo.com/2014/01/17/Exploring_PyMC3.html

But when I follow the example using pymc 2.3, I get the output and said that the API has changed UserWarning: MCMC () syntax is deprecated. Go through the nodes explicitly through M = MCMC (input). The syntax of MCMC () is deprecated. The request to transfer nodes explicitly through M = MCMC (input). .

This code:

%pylab inline
import scipy
import numpy as np
x = np.array(range(0,50))
y = np.random.uniform(low=0.0, high=40.0, size=200)
y = map((lambda a: a[0] + a[1]), zip(x,y))

import matplotlib.pyplot as plt
plt.scatter(x,y)

Above sample data generator works fine

import pymc as pm
import numpy as np

trace = None
with pm.Model() as model:         <<<<<<indicated as the error line
    alpha = pm.Normal('alpha', mu=0, sd=20)
    beta = pm.Normal('beta', mu=0, sd=20)
    sigma = pm.Uniform('sigma', lower=0, upper=20)

    y_est = alpha + beta * x

    likelihood = pm.Normal('y', mu=y_est, sd=sigma, observed=y)

    start = pm.find_MAP()
    step = pm.NUTS(state=start)
    trace = pm.sample(2000, step, start=start, progressbar=False)

    pm.traceplot(trace);
+4
source share
1 answer

@fonnesbeck , 3 Github, pypi 2.3. , github . !

+1

Source: https://habr.com/ru/post/1526622/


All Articles