Skip to content

Commit

Permalink
[BUG] fix test_plot_crossplot_interval for interval predictions (#67)
Browse files Browse the repository at this point in the history
This PR fixes an unreported bug with `test_plot_crossplot_interval` - it
would fail for interval predictions as internally the input would be
incorrectly identified as a distribution - as the check checks whether a
`quantiles` method is present, and `DataFrame`-s have this too, not just
distributions.

This is rectified by an explicit type check.

Tests for the input case are also added.
  • Loading branch information
fkiraly authored Sep 10, 2023
1 parent 6b15b1b commit 2bf7a80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion skpro/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def plot_crossplot_interval(y_true, y_pred, coverage=None, ax=None):

from matplotlib import pyplot

if hasattr(y_pred, "quantile"):
if hasattr(y_pred, "quantile") and not isinstance(y_pred, pd.DataFrame):
if coverage is None:
coverage = 0.9
quantile_pts = [0.5 - coverage / 2, 0.5, 0.5 + coverage / 2]
Expand Down
8 changes: 6 additions & 2 deletions skpro/utils/tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ def test_plot_crossplot_interval():
reg_proba = ResidualDouble(reg_mean, reg_resid)

reg_proba.fit(X, y)
y_pred = reg_proba.predict_proba(X)
y_pred_proba = reg_proba.predict_proba(X)

plot_crossplot_interval(y, y_pred_proba, coverage=0.8)
plot_crossplot_interval(y, y_pred_proba)

plot_crossplot_interval(y, y_pred)
y_pred_interval = reg_proba.predict_interval(X, coverage=0.7)
plot_crossplot_interval(y, y_pred_interval)


@pytest.mark.skipif(
Expand Down

0 comments on commit 2bf7a80

Please sign in to comment.