I was comparing two models with pm.compare and I wanted to visualize the values using pm.compare but I got an error. I’m also confused why the documentation mentions az.plot_compare?
Here’s the code:
comp_dic = {m1: trace_m1, m2: trace_m2}
df_comp_WAIC = pm.compare(comp_dic)
df_comp_WAIC
pm.compareplot(df_comp_WAIC)
Here’s the output:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-142-f1b04076e5ff> in <module>
----> 1 pm.compareplot(df_comp_WAIC)
~/anaconda3/lib/python3.7/site-packages/pymc3/plots/__init__.py in compareplot(*args, **kwargs)
81 else:
82 args[0] = comp_df
---> 83 return az.plot_compare(*args, **kwargs)
84
85 from .posteriorplot import plot_posterior_predictive_glm
~/anaconda3/lib/python3.7/site-packages/arviz/plots/compareplot.py in plot_compare(comp_df, insample_dev, plot_standard_error, plot_ic_diff, order_by_rank, figsize, textsize, plot_kwargs, ax)
107
108 if order_by_rank:
--> 109 comp_df.sort_values(by="rank", inplace=True)
110
111 if plot_ic_diff:
~/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py in sort_values(self, by, axis, ascending, inplace, kind, na_position)
4717
4718 by = by[0]
-> 4719 k = self._get_label_or_level_values(by, axis=axis)
4720
4721 if isinstance(ascending, (tuple, list)):
~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in _get_label_or_level_values(self, key, axis)
1704 values = self.axes[axis].get_level_values(key)._values
1705 else:
-> 1706 raise KeyError(key)
1707
1708 # Check for duplicates
KeyError: 'rank'