From 7e9bbb6ed7243925686f476cdaabcade01a43c2c Mon Sep 17 00:00:00 2001 From: Kartik Ayyer Date: Sun, 19 Apr 2020 07:00:00 +0200 Subject: [PATCH 1/4] Fix position of minimum line in plot_objective() Problem occurred when plot_dims is not the first N dimensions --- skopt/plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skopt/plots.py b/skopt/plots.py index 8f7c30416..9314966e8 100644 --- a/skopt/plots.py +++ b/skopt/plots.py @@ -717,7 +717,7 @@ def plot_objective(result, levels=10, n_points=40, n_samples=250, size=2, else: ax_ = ax ax_.plot(xi, yi) - ax_.axvline(minimum[i], linestyle="--", color="r", lw=1) + ax_.axvline(minimum[index], linestyle="--", color="r", lw=1) # lower triangle elif i > j: From 8dacf4dfa5614ca41b9578ecbca4a4bf116488c0 Mon Sep 17 00:00:00 2001 From: Kartik Ayyer Date: Sun, 19 Apr 2020 07:18:44 +0200 Subject: [PATCH 2/4] Add show_points and cmap options to plot_objective `show_points` allows user to decide whether to see evaluated points `cmap` allows user to choose color map for contour plot --- skopt/plots.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/skopt/plots.py b/skopt/plots.py index 9314966e8..5a76c1848 100644 --- a/skopt/plots.py +++ b/skopt/plots.py @@ -537,7 +537,8 @@ def partial_dependence(space, model, i, j=None, sample_points=None, def plot_objective(result, levels=10, n_points=40, n_samples=250, size=2, zscale='linear', dimensions=None, sample_source='random', - minimum='result', n_minimum_search=None, plot_dims=None): + minimum='result', n_minimum_search=None, plot_dims=None, + show_points=True, cmap='viridis_r'): """Plot a 2-d matrix with so-called Partial Dependence plots of the objective function. This shows the influence of each search-space dimension on the objective function. @@ -586,7 +587,7 @@ def plot_objective(result, levels=10, n_points=40, n_samples=250, size=2, levels : int, default=10 Number of levels to draw on the contour plot, passed directly - to `plt.contour()`. + to `plt.contourf()`. n_points : int, default=40 Number of points at which to evaluate the partial dependence @@ -654,6 +655,14 @@ def plot_objective(result, levels=10, n_points=40, n_samples=250, size=2, `sample_source` and/or `minimum` is set to 'expected_minimum' or 'expected_minimum_random'. + show_points: bool, default = True + Choose whether to show evaluated points in the + contour plots. + + cmap: str or Colormap, default = 'viridis_r' + Color map for contour plots. Passed directly to + `plt.contourf()` + Returns ------- ax : `Matplotlib.Axes` @@ -728,9 +737,10 @@ def plot_objective(result, levels=10, n_points=40, n_samples=250, size=2, index1, index2, samples, n_points) ax_.contourf(xi, yi, zi, levels, - locator=locator, cmap='viridis_r') - ax_.scatter(x_samples[:, index2], x_samples[:, index1], - c='k', s=10, lw=0.) + locator=locator, cmap=cmap) + if show_points: + ax_.scatter(x_samples[:, index2], x_samples[:, index1], + c='k', s=10, lw=0.) ax_.scatter(minimum[index2], minimum[index1], c=['r'], s=100, lw=0., marker='*') ylabel = "Partial dependence" From 5825c51f63d4f3634da88eeff82650ba1d33cd80 Mon Sep 17 00:00:00 2001 From: Kartik Ayyer Date: Sun, 19 Apr 2020 07:29:33 +0200 Subject: [PATCH 3/4] Fix xlim of diagonals in plot_objective --- skopt/plots.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/skopt/plots.py b/skopt/plots.py index 5a76c1848..66af014b7 100644 --- a/skopt/plots.py +++ b/skopt/plots.py @@ -429,6 +429,8 @@ def _format_scatter_plot_axes(ax, space, ylabel, plot_dims, else: # diagonal plots ax_.set_ylim(*diagonal_ylim) + low, high = dim_i.bounds + ax_.set_xlim(low, high) ax_.yaxis.tick_right() ax_.yaxis.set_label_position('right') ax_.yaxis.set_ticks_position('both') From 0d9c4f737353469d4bfe8b3880cf1146f012f06b Mon Sep 17 00:00:00 2001 From: Kartik Ayyer Date: Sun, 19 Apr 2020 08:04:48 +0200 Subject: [PATCH 4/4] Fix setting xlim with categorical spaces --- skopt/plots.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/skopt/plots.py b/skopt/plots.py index 66af014b7..f962cd780 100644 --- a/skopt/plots.py +++ b/skopt/plots.py @@ -429,8 +429,9 @@ def _format_scatter_plot_axes(ax, space, ylabel, plot_dims, else: # diagonal plots ax_.set_ylim(*diagonal_ylim) - low, high = dim_i.bounds - ax_.set_xlim(low, high) + if not iscat[i]: + low, high = dim_i.bounds + ax_.set_xlim(low, high) ax_.yaxis.tick_right() ax_.yaxis.set_label_position('right') ax_.yaxis.set_ticks_position('both')