From f605e4f7b2a42896c047386b124c6f0c0d1b6086 Mon Sep 17 00:00:00 2001 From: Joshua Date: Wed, 1 Jul 2020 16:54:32 +0200 Subject: [PATCH 1/3] Typo in Link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a97241c..b577b957 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **NOTE** *This repository is waiting for adoption and there might be longer waiting times for answers. However, feel free to report bugs or ask questions in the issues. -Last known working versions of major dependencies can be found [here](https://github.com/automl/issues/* +Last known working versions of major dependencies can be found [here](https://github.com/automl/issues/).* ## Configuration Assessment, Visualization and Evaluation From 48c7b3b52be33f6181f95294f459730508cb85c3 Mon Sep 17 00:00:00 2001 From: JessicaBorja Date: Tue, 23 Feb 2021 21:22:13 +0100 Subject: [PATCH 2/3] jupyter notebook plots for parameter importance --- .../configurator/parallel_coordinates.py | 14 +++++ .../base_parameter_importance.py | 18 ++++++ cave/analyzer/parameter_importance/fanova.py | 58 ++++++++++++++----- .../local_parameter_importance.py | 27 ++++++++- cave/plot/configurator_footprint.py | 2 +- 5 files changed, 102 insertions(+), 17 deletions(-) diff --git a/cave/analyzer/configurator/parallel_coordinates.py b/cave/analyzer/configurator/parallel_coordinates.py index 60086404..6c5e1832 100644 --- a/cave/analyzer/configurator/parallel_coordinates.py +++ b/cave/analyzer/configurator/parallel_coordinates.py @@ -5,6 +5,9 @@ import pandas as pd from ConfigSpace.configuration_space import ConfigurationSpace, Configuration from ConfigSpace.hyperparameters import NumericalHyperparameter, CategoricalHyperparameter +from bokeh.io import output_notebook +from bokeh.models.annotations import Title +from bokeh.plotting import show from bokeh.embed import components from bokeh.layouts import column from bokeh.models import Div @@ -235,3 +238,14 @@ def get_html(self, d=None, tooltip=None): result["tooltip"] = self.__doc__ d["Parallel Coordinates"] = result return result + + def get_jupyter(self): + bokeh_plots = self.plot_bokeh() + output_notebook() + if len(self.result) == 0: + if(bokeh_plots): + show(bokeh_plots) + return + for budget, bokeh_plot in bokeh_plots.items(): + plot = column( Div(text=budget), bokeh_plot) # to add a title + show(plot) \ No newline at end of file diff --git a/cave/analyzer/parameter_importance/base_parameter_importance.py b/cave/analyzer/parameter_importance/base_parameter_importance.py index 261a8ba9..1b50f985 100644 --- a/cave/analyzer/parameter_importance/base_parameter_importance.py +++ b/cave/analyzer/parameter_importance/base_parameter_importance.py @@ -109,3 +109,21 @@ def get_html(self, d=None, tooltip=None): "and the whiskers are quartiles."} return super().get_html(d, tooltip) + + def get_jupyter(self): + from IPython.core.display import HTML, display + import matplotlib.pyplot as plt + from matplotlib import style + import matplotlib + matplotlib.use( 'nbAgg' ) + for b, data in self.result['Importances Per Parameter'].items(): + im_list = [] + for component, _ in data.items(): + if(component == "figure"): + im_list += [plt.imread(f) for f in data[component]] + f, axes = plt.subplots(1, len(im_list), figsize = (4*len(im_list),3)) + for img, ax in zip(im_list, axes): + ax.imshow(img) + ax.axis('off') + f.suptitle(b, fontsize=14) + plt.show() diff --git a/cave/analyzer/parameter_importance/fanova.py b/cave/analyzer/parameter_importance/fanova.py index 790b5279..6b54c102 100644 --- a/cave/analyzer/parameter_importance/fanova.py +++ b/cave/analyzer/parameter_importance/fanova.py @@ -99,19 +99,47 @@ def parse_pairwise(p): return result + def _plot_img_lst(self, img_lst, max_cols, sup_title): + import matplotlib.pyplot as plt + import math + rows = math.ceil( len(img_lst)/max_cols ) + figure, axes = plt.subplots(rows, max_cols, figsize = (4*max_cols,3*rows)) + i = 0 + for r in range(rows): + for c in range(max_cols): + if(i Date: Mon, 1 Mar 2021 12:51:22 +0100 Subject: [PATCH 3/3] matplotlib backend fix --- .../base_parameter_importance.py | 7 +++-- cave/analyzer/parameter_importance/fanova.py | 29 ++++++++++++------- .../local_parameter_importance.py | 29 ++++++++++++------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/cave/analyzer/parameter_importance/base_parameter_importance.py b/cave/analyzer/parameter_importance/base_parameter_importance.py index 1b50f985..5a57f287 100644 --- a/cave/analyzer/parameter_importance/base_parameter_importance.py +++ b/cave/analyzer/parameter_importance/base_parameter_importance.py @@ -113,15 +113,16 @@ def get_html(self, d=None, tooltip=None): def get_jupyter(self): from IPython.core.display import HTML, display import matplotlib.pyplot as plt - from matplotlib import style import matplotlib - matplotlib.use( 'nbAgg' ) + from importlib import reload + matplotlib.use('nbAgg') # GUI backend + matplotlib = reload(matplotlib) for b, data in self.result['Importances Per Parameter'].items(): im_list = [] for component, _ in data.items(): if(component == "figure"): im_list += [plt.imread(f) for f in data[component]] - f, axes = plt.subplots(1, len(im_list), figsize = (4*len(im_list),3)) + f, axes = plt.subplots(1, len(im_list), figsize = (6*len(im_list),5)) for img, ax in zip(im_list, axes): ax.imshow(img) ax.axis('off') diff --git a/cave/analyzer/parameter_importance/fanova.py b/cave/analyzer/parameter_importance/fanova.py index 6b54c102..a72ae9f0 100644 --- a/cave/analyzer/parameter_importance/fanova.py +++ b/cave/analyzer/parameter_importance/fanova.py @@ -99,17 +99,21 @@ def parse_pairwise(p): return result - def _plot_img_lst(self, img_lst, max_cols, sup_title): - import matplotlib.pyplot as plt + def _plot_img_lst(self, plt, img_lst, max_cols, sup_title): import math rows = math.ceil( len(img_lst)/max_cols ) - figure, axes = plt.subplots(rows, max_cols, figsize = (4*max_cols,3*rows)) + figure, axes = plt.subplots(rows, max_cols, figsize = (5*max_cols,5*rows)) i = 0 for r in range(rows): for c in range(max_cols): - if(i 1): + if(i < len(img_lst)): + axes[r, c].imshow(img_lst[i]) + axes[r, c].axis('off') + else: + if(i < len(img_lst)): + axes[c].imshow(img_lst[i]) + axes[c].axis('off') i += 1 figure.suptitle(sup_title, fontsize=14) @@ -122,11 +126,14 @@ def get_jupyter(self): # # Show plots # display(*list([Image(filename=d["figure"]) for d in result['Marginals'].values()])) # display(*list([Image(filename=d["figure"]) for d in result['Pairwise Marginals'].values()])) + # Reload matplotlib backend to avoid GUI blank plots from IPython.core.display import HTML, display - import matplotlib.pyplot as plt - from matplotlib import style import matplotlib - matplotlib.use( 'nbAgg' ) + import matplotlib.pyplot as plt + from importlib import reload + matplotlib.use('nbAgg') # GUI backend + matplotlib = reload(matplotlib) + for b, result in self.result['Importances Per Parameter'].items(): # Show Table display(HTML(result["Importance"]["table"])) @@ -136,10 +143,10 @@ def get_jupyter(self): marginals_lst = [plt.imread(hp['figure']) for hp in result['Marginals'].values()] pairws_marginals_lst = [plt.imread(hp['figure']) for hp in result['Pairwise Marginals'].values()] - f_marginals = self._plot_img_lst(marginals_lst, + f_marginals = self._plot_img_lst(plt, marginals_lst, max_cols = 2, sup_title = b + ": Marginals") - f_pairwise_marginals = self._plot_img_lst(pairws_marginals_lst, \ + f_pairwise_marginals = self._plot_img_lst(plt, pairws_marginals_lst,\ max_cols = 2, sup_title = b + ": Pairwise Marginals") plt.show() diff --git a/cave/analyzer/parameter_importance/local_parameter_importance.py b/cave/analyzer/parameter_importance/local_parameter_importance.py index 5a87ada8..5cf9849d 100644 --- a/cave/analyzer/parameter_importance/local_parameter_importance.py +++ b/cave/analyzer/parameter_importance/local_parameter_importance.py @@ -27,7 +27,7 @@ def get_name(self): def postprocess(self, pimp, output_dir): param_imp = pimp.evaluator.evaluated_parameter_importance plots = OrderedDict() - for p, i in [(k, v) for k, v in sorted(param_imp.items(), + for p, _ in [(k, v) for k, v in sorted(param_imp.items(), key=operator.itemgetter(1), reverse=True)]: plots[p] = os.path.join(output_dir, 'lpi', p + '.png') return OrderedDict([ @@ -40,23 +40,32 @@ def get_jupyter(self): # for plots, d in budget_dict.items(): # if(plots != 'Interactive Plots'): # display(Image(filename = d["figure"])) + # Reload matplotlib backend to avoid GUI blank plots from IPython.core.display import HTML, display + import matplotlib import matplotlib.pyplot as plt - from matplotlib import style - import matplotlib, math - matplotlib.use( 'nbAgg' ) + from importlib import reload + import math + matplotlib.use('nbAgg') # GUI backend + matplotlib = reload(matplotlib) + max_cols = 2 for b, data in self.result['Importances Per Parameter'].items(): - im_list = [ plt.imread( c['figure'] ) for c in data.values() if 'figure' in c ] + img_lst = [ plt.imread( c['figure'] ) for c in data.values() if 'figure' in c ] # Plot in grid - rows = math.ceil( len(im_list)/max_cols ) - figure, axes = plt.subplots(rows, max_cols, figsize = (4*max_cols,3*rows)) + rows = math.ceil( len(img_lst)/max_cols ) + figure, axes = plt.subplots(rows, max_cols, figsize = (5*max_cols,4*rows)) i = 0 for r in range(rows): for c in range(max_cols): - if(i 1): + if(i < len(img_lst)): + axes[r, c].imshow(img_lst[i]) + axes[r, c].axis('off') + else: + if(i < len(img_lst)): + axes[c].imshow(img_lst[i]) + axes[c].axis('off') i += 1 figure.suptitle(b, fontsize=14)