Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Energy Plot
===========
_thumb: .7, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("centered_eight")
az.plot_energy(data, figsize=(12, 8))
"""
Violinplot
==========
_thumb: .2, .8
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("non_centered_eight")
az.plot_violin(data, var_names=["mu", "tau"])
"""
Rank plot
=========
_thumb: .1, .8
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("centered_eight")
az.plot_rank(data, var_names=("tau", "mu"))
"""
Compare Plot
============
_thumb: .5, .5
"""
import arviz as az
import numpy as np
import pymc3 as pm
az.style.use('arviz-darkgrid')
# Data of the Eight Schools Model
J = 8
y = np.array([28., 8., -3., 7., -1., 1., 18., 12.])
sigma = np.array([15., 10., 16., 11., 9., 11., 10., 18.])
with pm.Model('Centered Eight Schools') as centered_eight:
mu = pm.Normal('mu', mu=0, sd=5)
tau = pm.HalfCauchy('tau', beta=5)
theta = pm.Normal('theta', mu=mu, sd=tau, shape=J)
obs = pm.Normal('obs', mu=theta, sd=sigma, observed=y)
centered_eight_trace = pm.sample()
with pm.Model('Non-Centered Eight Schools') as non_centered:
"""
Forest Plot
===========
_thumb: .5, .8
"""
import arviz as az
az.style.use("arviz-darkgrid")
centered_data = az.load_arviz_data("centered_eight")
non_centered_data = az.load_arviz_data("non_centered_eight")
axes = az.plot_forest(
[centered_data, non_centered_data], model_names=["Centered", "Non Centered"], var_names=["mu"]
)
axes[0].set_title("Estimated theta for eight schools model")
"""
Parallel Plot
=============
_thumb: .2, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("centered_eight")
ax = az.plot_parallel(data, var_names=["theta", "tau", "mu"])
ax.set_xticklabels(ax.get_xticklabels(), rotation=70)
"""
Parallel Plot
=============
_thumb: .2, .5
"""
import arviz as az
import numpy as np
import pymc3 as pm
az.style.use('arviz-darkgrid')
# Data of the Eight Schools Model
J = 8
y = np.array([28., 8., -3., 7., -1., 1., 18., 12.])
sigma = np.array([15., 10., 16., 11., 9., 11., 10., 18.])
with pm.Model() as centered_eight:
mu = pm.Normal('mu', mu=0, sd=5)
tau = pm.HalfCauchy('tau', beta=5)
theta = pm.Normal('theta', mu=mu, sd=tau, shape=J)
obs = pm.Normal('obs', mu=theta, sd=sigma, observed=y)
centered_eight_trace = pm.sample()
az.parallelplot(centered_eight_trace, var_names=['theta', 'tau', 'mu'])
"""
Pair Plot
=========
_thumb: .2, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
centered = az.load_arviz_data("centered_eight")
coords = {"school": ["Choate", "Deerfield"]}
az.plot_pair(
centered, var_names=["theta", "mu", "tau"], coords=coords, divergences=True, textsize=22
)
"""
Posterior Predictive Check Plot
===============================
_thumb: .6, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("non_centered_eight")
az.plot_ppc(data, alpha=0.03, figsize=(12, 6), textsize=14)
"""
Posterior Predictive Check Cumulative Plot
==========================================
_thumb: .6, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("non_centered_eight")
az.plot_ppc(data, alpha=0.3, kind="cumulative", figsize=(12, 6), textsize=14)