Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix in-sample deviance #1435

Merged
merged 4 commits into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
* Remove ticks and spines in `plot_violin` ([1426 ](https://github.com/arviz-devs/arviz/pull/1426))
* Use circular KDE function and fix tick labels in circular `plot_trace` ([1428](https://github.com/arviz-devs/arviz/pull/1428))
* Fix `pair_plot` for mixed discrete and continuous variables ([1434](https://github.com/arviz-devs/arviz/pull/1434))
* Fix in-sample deviance in `plot_compare` ([1435](https://github.com/arviz-devs/arviz/pull/1435))

### Deprecation

10 changes: 9 additions & 1 deletion arviz/plots/backends/bokeh/compareplot.py
Original file line number Diff line number Diff line change
@@ -105,8 +105,16 @@ def plot_compare(
ax.multi_line(err_xs, err_ys, line_color=plot_kwargs.get("color_ic", "black"))

if insample_dev:
scale = comp_df[f"{information_criterion}_scale"][0]
p_ic = comp_df[f"p_{information_criterion}"]
if scale == "log":
correction = p_ic
elif scale == "negative_log":
correction = -p_ic
elif scale == "deviance":
correction = -(2 * p_ic)
ax.circle(
comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
comp_df[information_criterion] + correction,
yticks_pos[::2],
line_color=plot_kwargs.get("color_insample_dev", "black"),
fill_color=plot_kwargs.get("color_insample_dev", "black"),
10 changes: 9 additions & 1 deletion arviz/plots/backends/matplotlib/compareplot.py
Original file line number Diff line number Diff line change
@@ -82,8 +82,16 @@ def plot_compare(
)

if insample_dev:
scale = comp_df[f"{information_criterion}_scale"][0]
p_ic = comp_df[f"p_{information_criterion}"]
if scale == "log":
correction = p_ic
elif scale == "negative_log":
correction = -p_ic
elif scale == "deviance":
correction = -(2 * p_ic)
ax.plot(
comp_df[information_criterion] - (2 * comp_df["p_" + information_criterion]),
comp_df[information_criterion] + correction,
yticks_pos[::2],
color=plot_kwargs.get("color_insample_dev", "k"),
marker=plot_kwargs.get("marker_insample_dev", "o"),
10 changes: 0 additions & 10 deletions arviz/tests/base_tests/test_plots_bokeh.py
Original file line number Diff line number Diff line change
@@ -326,16 +326,6 @@ def test_plot_compare(models, kwargs):
assert axes


def test_plot_compare_manual(models):
"""Test compare plot without scale column"""
model_compare = compare({"Model 1": models.model_1, "Model 2": models.model_2})

# remove "scale" column
del model_compare["loo_scale"]
axes = plot_compare(model_compare, backend="bokeh", show=False)
assert axes


def test_plot_compare_no_ic(models):
"""Check exception is raised if model_compare doesn't contain a valid information criterion"""
model_compare = compare({"Model 1": models.model_1, "Model 2": models.model_2})
10 changes: 0 additions & 10 deletions arviz/tests/base_tests/test_plots_matplotlib.py
Original file line number Diff line number Diff line change
@@ -937,16 +937,6 @@ def test_plot_compare(models, kwargs):
assert axes


def test_plot_compare_manual(models):
"""Test compare plot without scale column"""
model_compare = compare({"Model 1": models.model_1, "Model 2": models.model_2})

# remove "scale" column
del model_compare["loo_scale"]
axes = plot_compare(model_compare)
assert axes


def test_plot_compare_no_ic(models):
"""Check exception is raised if model_compare doesn't contain a valid information criterion"""
model_compare = compare({"Model 1": models.model_1, "Model 2": models.model_2})