(gallery_compare)=

# Predictive model comparison

Compare multiple models using predictive accuracy estimated using PSIS-LOO-CV.
Usually the DataFrame ``cmp_df`` is generated using ArviZ's ```compare` function.



::::::{tab-set}
:class: full-width
:sync-group: backend

:::::{tab-item} Matplotlib
:sync: matplotlib

![Matplotlib version of plot_compare](_images/plot_compare.png)

:::::

:::::{tab-item} Bokeh
:sync: bokeh

```{bokeh-plot}
:source-position: none

from bokeh.plotting import show

import pandas as pd

import arviz_plots as azp

azp.style.use("arviz-variat")


cmp_df = pd.DataFrame(
{
"elpd": [-4.5, -14.3, -16.2],
"p": [2.6, 2.3, 2.1],
"elpd_diff": [0, 9.7, 11.3],
"weight": [0.9, 0.1, 0],
"se": [2.3, 2.7, 2.3],
"dse": [0, 2.7, 2.3],
"warning": [False, False, False],
},
index=["Model B", "Model A", "Model C"]
)

pc = azp.plot_compare(cmp_df, backend="bokeh")  # change to preferred backend


# for some reason the bokeh plot extension needs explicit use of show
show(pc.viz["figure"].item() if pc.viz["figure"].item() is not None else pc.viz["plot"].item())
```

Link to this page with the [bokeh tab selected](https://arviz-plots.readthedocs.io/en/latest//gallery/plot_compare.html?backend=bokeh#synchronised-tabs)
:::::

:::::{tab-item} Plotly
:sync: plotly

```{jupyter-execute}
:hide-code:

import pandas as pd

import arviz_plots as azp

azp.style.use("arviz-variat")


cmp_df = pd.DataFrame(
{
"elpd": [-4.5, -14.3, -16.2],
"p": [2.6, 2.3, 2.1],
"elpd_diff": [0, 9.7, 11.3],
"weight": [0.9, 0.1, 0],
"se": [2.3, 2.7, 2.3],
"dse": [0, 2.7, 2.3],
"warning": [False, False, False],
},
index=["Model B", "Model A", "Model C"]
)

pc = azp.plot_compare(cmp_df, backend="plotly")  # change to preferred backend
pc.show()
```

Link to this page with the [plotly tab selected](https://arviz-plots.readthedocs.io/en/latest//gallery/plot_compare.html?backend=plotly#synchronised-tabs)
:::::
::::::

```{literalinclude} _scripts/plot_compare.py
:emphasize-lines: 21
```



:::{seealso}
API Documentation: {func}`~arviz_plots.plot_compare`
:::



## Other examples with `plot_compare`

```{eval-rst}
.. minigallery:: plot_compare
```


:::{div} example-plot-download
{download}`Download Python Source Code: plot_compare.py<_scripts/plot_compare.py>`
:::
