<jupyter_start><jupyter_text>MCMC Model Visual DiagnosticsIn this section, we will introduce a suite of diagnostic plots available in Orbit- Density histogram- Trace plot- Pair plot- Forest plot- Posterior plot We leveraged [arviz](https://arviz-devs.github.io/arviz/index.html) for the plotting. ArviZ is a Python package for exploratory analysis of Bayesian models, includes functions for posterior analysis, data storage, model checking, comparison and diagnostics.<jupyter_code>import pandas as pd
import numpy as np
from orbit.models.lgt import LGTFull
from orbit.models.dlt import DLTFull
import arviz as az
from orbit.utils.dataset import load_iclaims
from orbit.diagnostics.plot import plot_param_diagnostics

import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>raw_df = load_iclaims()
raw_df.dtypes
raw_df.head(5)
df=raw_df.copy()
test_size=52
train_df=df[:-test_size]
test_df=df[-test_size:]<jupyter_output><empty_output><jupyter_text>Fit a Model<jupyter_code>DATE_COL="week"
RESPONSE_COL="claims"
REGRESSOR_COL=['trend.unemploy', 'trend.filling', 'trend.job']
dlt = DLTFull(
    response_col=RESPONSE_COL,
    date_col=DATE_COL,
    regressor_col=REGRESSOR_COL,
    regressor_sign=["+", '+', '='], 
    seasonality=52,
    num_warmup=2000,
    num_sample=2000,
    chains=4,
)
dlt.fit(df=train_df)<jupyter_output>WARNING:pystan:Maximum (flat) parameter count (1000) exceeded: skipping diagnostic tests for n_eff and Rhat.
To run all diagnostics call pystan.check_hmc_diagnostics(fit)<jupyter_text>Posterior Diagnostic Viz  trace plot<jupyter_code>plot_param_diagnostics(dlt, which='trace', kind="trace", 
                       legend=True,
                       chain_prop={"color": ["r", "b","g","y"]});
plot_param_diagnostics(dlt, which='trace', kind="rank_bars",
                       legend=True,
                       chain_prop={"color": ["r", "b","g","y"]});
plot_param_diagnostics(dlt, which='trace', kind="rank_vlines",
                       legend=True,
                       chain_prop={"color": ["r", "b","g","y"]});<jupyter_output><empty_output><jupyter_text>density plot<jupyter_code>plot_param_diagnostics(dlt, which='density');<jupyter_output><empty_output><jupyter_text>pair plot<jupyter_code>plot_param_diagnostics(dlt, which='pair');<jupyter_output><empty_output><jupyter_text>forest plot<jupyter_code>plot_param_diagnostics(dlt, which='forest');
plot_param_diagnostics(dlt, which='forest', kind='ridgeplot', colors='white', combined=True);<jupyter_output><empty_output><jupyter_text>posterior plot<jupyter_code>plot_param_diagnostics(dlt, which='posterior');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12342007434944238, 'fraction_numerical': 0.006691449814126394, 'mean_word_length': 6.026109660574413, 'pattern_counts': {'":': 3, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '284606', 'license': 'Apache-2.0', 'n_tokens_mistral': 959, 'n_tokens_neox': 912, 'n_words': 169, 'path': 'docs/tutorials/model_diagnostics.ipynb', 'repo_name': 'changdaniel/orbit', 'size': '2690'}