Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
LOO-PIT Overlay Plot
====================
_thumb: .5, .7
"""
import arviz as az
az.style.use("arviz-darkgrid")
idata = az.load_arviz_data("non_centered_eight")
az.plot_loo_pit(idata=idata, y="obs", color="indigo")
"""
LOO-PIT ECDF Plot
=================
_thumb: .5, .7
"""
import arviz as az
az.style.use("arviz-darkgrid")
idata = az.load_arviz_data("radon")
log_like = idata.sample_stats.log_likelihood.sel(chain=0).values.T
log_weights = az.psislw(-log_like)[0]
az.plot_loo_pit(idata, y="y_like", log_weights=log_weights, ecdf=True, color="maroon")
"""
Quantile MCSE Errobar Plot
==========================
_thumb: .6, .4
"""
import arviz as az
data = az.load_arviz_data("radon")
ax = az.plot_mcse(data, var_names=["sigma_a"], color="red", errorbar=True, backend="bokeh")
"""
Forest Plot
===========
_thumb: .5, .8
"""
import arviz as az
centered_data = az.load_arviz_data("centered_eight")
non_centered_data = az.load_arviz_data("non_centered_eight")
ax = az.plot_forest(
[centered_data, non_centered_data],
model_names=["Centered", "Non Centered"],
var_names=["mu"],
backend="bokeh",
)
"""
Ridgeplot
=========
_thumb: .8, .5
"""
import arviz as az
rugby_data = az.load_arviz_data("rugby")
ax = az.plot_forest(
rugby_data,
kind="ridgeplot",
var_names=["defs"],
linewidth=4,
combined=True,
ridgeplot_overlap=1.5,
colors="blue",
figsize=(9, 4),
backend="bokeh",
)
import arviz as az
model_compare = az.compare({'Centered 8 schools': az.load_arviz_data('centered_eight'),
'Non-centered 8 schools': az.load_arviz_data('non_centered_eight')})
az.plot_compare(model_compare)
"""
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
)
"""
Traceplot
=========
_thumb: .1, .8
"""
import arviz as az
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("non_centered_eight")
az.plot_trace(data, var_names=("tau", "mu"))
"""
ELPD Plot
=========
_thumb: .6, .5
"""
import arviz as az
az.style.use("arviz-darkgrid")
d1 = az.load_arviz_data("centered_eight")
d2 = az.load_arviz_data("non_centered_eight")
az.plot_elpd({"Centered eight": d1, "Non centered eight": d2}, xlabels=True)
"""
KDE Plot
========
_thumb: .2, .8
"""
import arviz as az
import numpy as np
az.style.use("arviz-darkgrid")
data = az.load_arviz_data("centered_eight")
# Combine posterior draws for from xarray of (4,500) to ndarray (2000,)
y_hat = np.concatenate(data.posterior_predictive["obs"].values)
ax = az.plot_kde(
y_hat,
label="Estimated Effect\n of SAT Prep",
rug=True,
plot_kwargs={"linewidth": 2, "color": "black"},
rug_kwargs={"color": "black"},
)