8000 MNT: fix plot_evaluation when skipping dimension, add test by QuentinSoubeyran · Pull Request #1066 · scikit-optimize/scikit-optimize · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

MNT: fix plot_evaluation when skipping dimension, add test #1066

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
8000

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
9 changes: 9 additions & 0 deletions doc/whats_new/v0.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ Version 0.9.0
for scikit-learn >= 1.0. :pr:`1063`
- Minor documentation improvements.
- Various small bugs and fixes.
:pr:`988`

Version 0.9.1
=============

- |Fix| Fix `skopt.plots.plot_evaluations` incorrectly handling dimensions
as categorical dimensions when constant dimension are ignored due to wrong
indexing.
:pr:`1066`
4 changes: 2 additions & 2 deletions skopt/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def plot_evaluations(result, bins=20, dimensions=None,
for j in range(n_dims):
if i == j:
index, dim = plot_dims[i]
if iscat[j]:
if iscat[index]:
bins_ = len(dim.categories)
elif dim.prior == 'log-uniform':
low, high = space.bounds[index]
Expand All @@ -839,7 +839,7 @@ def plot_evaluations(result, bins=20, dimensions=None,
else:
ax_ = ax[i, i]
ax_.hist(samples[:, index], bins=bins_,
range=None if iscat[j] else dim.bounds)
range=None if iscat[index] else dim.bounds)

# lower triangle
elif i > j:
Expand Down
22 changes: 22 additions & 0 deletions skopt/tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ def objective(params):
# Look into how matplotlib does this.


def test_plots_skip_constant():
"""Test that constant dimension are properly skipped"""
SPACE = [
Categorical([0], name="dummy"),
Categorical([0], name="dummy"),
Integer(1, 20, name='max_depth'),
Integer(1, 20, name='max_depth'),
]
X, y = load_breast_cancer(return_X_y=True)

def objective(params):
clf = DecisionTreeClassifier(random_state=3,
**{dim.name: val
for dim, val in zip(SPACE, params)
if dim.name != 'dummy'})
return -np.mean(cross_val_score(clf, X, y))
res = gp_minimize(objective, SPACE, n_calls=10, random_state=3)
print(res.space)
print(plots._map_categories(res.space, res.x_iters, res.x))
plots.plot_evaluations(res)


@pytest.mark.fast_test
def test_evaluate_min_params():
res = gp_minimize(bench3,
Expand Down
0