私はOsvaldo MartinのPyMC3の例を取得しようとしていますPythonでベイジアン解析が動作しています。 matplotlibのを使用して、次のコードは正常に動作します(つまり、チャートが表示されている)中にWindows 10で、:PyMC3トレースプロットが表示されない
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
def posterior_grid(grid_points=100, heads=6, tosses=9):
"""
A grid implementation for the coin-flip problem
"""
grid = np.linspace(0, 1, grid_points)
prior = 0.5 - abs(grid - 0.5)
likelihood = stats.binom.pmf(heads, tosses, grid)
unstd_posterior = likelihood * prior
posterior = unstd_posterior/unstd_posterior.sum()
return grid, posterior
if __name__ == "__main__":
points = 100
h, n = 1, 4
grid, posterior = posterior_grid(points, h, n)
plt.plot(grid, posterior, 'o-', label='heads = {}\ntosses = {}'.format(h, n))
plt.xlabel(r'$\theta$')
plt.legend(loc=0)
plt.show()
...私は次のことを得ることができない - PyMC3のtraceplot使用する - グラフを表示するに:
import pymc3 as pm
import numpy as np
import scipy.stats as stats
if __name__ == "__main__":
np.random.seed(123)
n_experiments = 4
theta_real = 0.35
data = stats.bernoulli.rvs(p=theta_real, size=n_experiments)
print(data)
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});
コードは実行されて正常に終了しますが、グラフは表示されません。
私はIntelliJ IDEAをPythonプラグインで、Anacondaコンソールウィンドウからルート環境用に、IPythonから試しました。 IPythonで
、私は、コンソールに次のような出力が得られます。
Out[3]:
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000024BDD622F60>,
<matplotlib.axes._subplots.AxesSubplot object at 0x0000024BDD667208>]], dtype=object)
...そう、明らかに何かが起こっています。しかし、どのようにして結果をグラフとして表示できますか? scipyのダウンロード0.18.1
- Ipython 5.0
- numpyの1.11.1
- : は、私はまた、Pythonの3.5でブックに記載されている正確なライブラリのバージョンが、それでも無traceplotチャートを試してみました
- パンダ0.18.1
- matplotlibの1.5.3
- Seaborn 0.7.1
- PyMC3 3.0