Arviz Issues following Tutorials

Hi.

I’ve been trying to follow along the data containers tutorial: Using Data Containers — PyMC example gallery

To try understand the data structures and model specification better. (I’m only used to using the R style formula expression).

I’m encountering issues with arviz graphics and cant troubleshoot it down through FAQs or googlefu. My version of pymc was installed via pip according to these instructions; Installation — PyMC dev documentation and I have installed all the extra g++ backend bits needed for speedy sampling. I’m executing code from a jupyter notebook in vscode.

I’m running;

import arviz as az

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc as pm
import xarray as xr
from numpy.random import default_rng

%config InlineBackend.figure_format = 'retina'
RANDOM_SEED = sum(map(ord, "Data Containers in PyMC"))
rng = default_rng(RANDOM_SEED)

plt.rcParams["figure.constrained_layout.use"] = True
data = pd.read_csv(pm.get_data("babies.csv"))
data.plot.scatter("Month", "Length", alpha=0.4, color="k")
df_rugby = pd.read_csv(pm.get_data("rugby.csv"), index_col=0)
print(f"Running on PyMC v{pm.__version__}")

with pm.Model(
    coords={"obs_idx": np.arange(len(data)), "parameter": ["intercept", "slope"]}
) as model_babies:
    mean_params = pm.Normal("mean_params", sigma=10, dims=["parameter"])
    sigma_params = pm.Normal("sigma_params", sigma=10, dims=["parameter"])
    month = pm.Data("month", data.Month.values.astype(float), dims=["obs_idx"])

    mu = pm.Deterministic("mu", mean_params[0] + mean_params[1] * month**0.5, dims=["obs_idx"])
    sigma = pm.Deterministic("sigma", sigma_params[0] + sigma_params[1] * month, dims=["obs_idx"])

    length = pm.Normal("length", mu=mu, sigma=sigma, observed=data.Length, dims=["obs_idx"])

    idata_babies = pm.sample()

az.plot_lm(

    idata_babies,

    ci_prob=\[0.6, 0.95\],

    visuals={

        "pe_line": {"color": "C0"},

        "ci_band": {"alpha": 0.3},

        "observed_scatter": {"marker": "C6"},

    },

)

and getting an error message of

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 az.plot_lm(
      2     idata_babies,
      3     ci_prob=[0.6, 0.95],
      4     visuals={

TypeError: plot_lm() got an unexpected keyword argument 'ci_prob'

Similarly with the later plot_dist;

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 3
      1 ref_length = 51.5
      2 
----> 3 pc = az.plot_dist(
      4     idata_babies,
      5     group="predictions",
      6     labeller=az.labels.DimCoordLabeller(),

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\arviz\plots\distplot.py:232, in plot_dist(values, values2, color, kind, cumulative, label, rotated, rug, bw, quantiles, contour, fill_last, figsize, textsize, plot_kwargs, fill_kwargs, rug_kwargs, contour_kwargs, contourf_kwargs, pcolormesh_kwargs, hist_kwargs, is_circular, ax, backend, backend_kwargs, show, **kwargs)
    229 backend = backend.lower()
    231 plot = get_plotting_function("plot_dist", "distplot", backend)
--> 232 ax = plot(**dist_plot_args)
    233 return ax

TypeError: plot_dist() got an unexpected keyword argument 'group'

I’m assuming it must be something to do with version mismatches, but the Arviz documentation shows both of these keywords being expected so I’m a little confused.

The notebook seems to be using ArviZ>=1 and a local PyMC install tagged 5.28.0+58.gf58491a3 but as it is already compatible with ArviZ>=1 it means is is a few commits before the 6.0 release. To be able to run the notebook as is you’ll need to install PyMC>=6 (which requires ArviZ>=1). However, from the error messages you got it looks like you have ArviZ<1 installed.

If you did a fresh install and didn’t restrict ArviZ<1 nor PyMC<6 you might need to upgrade the Python version as IIRC, both require python 3.12 or higher so being on 3.11 would inadvertedly force the constrain on you

Thank you.

Yes I had an old install of Python on my machine which was causing pip to install v3.11 compatable version of pymc and its dependancies. Removing that and forcing a fresh install has fixed my issues.

Back to trying to figure out the data structures!