SheffieldML / GPyOpt

Gaussian Process Optimization using GPy
BSD 3-Clause "New" or "Revised" License
927 stars 261 forks source link

Getting an error when running myBopt.plot_acquisition() from tutorial #355

Open fedeotto opened 3 years ago

fedeotto commented 3 years ago

Just by running the tutorial on my notebook I get an error when it comes to run

myBopt.plot_acquisition()

The error:

`Traceback (most recent call last):

File "C:\Users\hp\Desktop\PHD\Projects\untitled3.py", line 33, in myBopt.plot_acquisition()

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\core\bo.py", line 284, in plot_acquisition return plot_acquisition(self.acquisition.space.get_bounds(),

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\plotting\plots_bo.py", line 64, in plot_acquisition model.plot_density(bounds[0], alpha=.5)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 257, in plot_density plots = _plot_density(self, canvas, helper_data, helper_prediction, label, **kwargs)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 271, in _plot_density fills.append(pl().fill_gradient(

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\matplot_dep\plot_definitions.py", line 244, in fill_gradient ax._process_unit_info(xdata=X, ydata=y1)

TypeError: _process_unit_info() got an unexpected keyword argument 'xdata'

runcell(0, 'C:/Users/hp/Desktop/PHD/Projects/untitled3.py') Traceback (most recent call last):

File "C:\Users\hp\Desktop\PHD\Projects\untitled3.py", line 33, in myBopt.plot_acquisition()

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\core\bo.py", line 284, in plot_acquisition return plot_acquisition(self.acquisition.space.get_bounds(),

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\plotting\plots_bo.py", line 64, in plot_acquisition model.plot_density(bounds[0], alpha=.5)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 257, in plot_density plots = _plot_density(self, canvas, helper_data, helper_prediction, label, **kwargs)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 271, in _plot_density fills.append(pl().fill_gradient(

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\matplot_dep\plot_definitions.py", line 244, in fill_gradient ax._process_unit_info(xdata=X, ydata=y1)

TypeError: _process_unit_info() got an unexpected keyword argument 'xdata'

runcell(0, 'C:/Users/hp/Desktop/PHD/Projects/untitled3.py') Traceback (most recent call last):

File "C:\Users\hp\Desktop\PHD\Projects\untitled3.py", line 33, in myBopt.plot_acquisition()

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\core\bo.py", line 284, in plot_acquisition return plot_acquisition(self.acquisition.space.get_bounds(),

File "C:\Users\hp\anaconda3\lib\site-packages\GPyOpt\plotting\plots_bo.py", line 64, in plot_acquisition model.plot_density(bounds[0], alpha=.5)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 257, in plot_density plots = _plot_density(self, canvas, helper_data, helper_prediction, label, **kwargs)

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\gpy_plot\gp_plots.py", line 271, in _plot_density fills.append(pl().fill_gradient(

File "C:\Users\hp\anaconda3\lib\site-packages\GPy\plotting\matplot_dep\plot_definitions.py", line 244, in fill_gradient ax._process_unit_info(xdata=X, ydata=y1)

TypeError: _process_unit_info() got an unexpected keyword argument 'xdata`

wak-shogo commented 3 years ago

I had a same error, and successfully fixed as follows. This problem would be caused by the change of matplotlib function _process_unit_info(). For me, downgrading matplotlib to 3.1.3 ( pip install matplotlib==3.1.3) works.

mininkor commented 2 years ago

Hi,

I downgraded the verison to 3.1.3 as describe above. But then, it started to show another error.

here is an error code.


AttributeError Traceback (most recent call last) /var/folders/9r/_5r0zb5x46g3430cgtbjc0mw0000gn/T/ipykernel_2141/3669738409.py in 2 myBopt_1d = BayesianOptimization(f=obj_func, domain=domain) 3 myBopt_1d.run_optimization(max_iter=5) ----> 4 myBopt_1d.plot_acquisition()

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/GPyOpt/core/bo.py in plot_acquisition(self, filename, label_x, label_y) 282 model_to_plot = self.model 283 --> 284 return plot_acquisition(self.acquisition.space.get_bounds(), 285 model_to_plot.model.X.shape[1], 286 model_to_plot.model,

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/GPyOpt/plotting/plots_bo.py in plot_acquisition(bounds, input_dim, model, Xdata, Ydata, acquisition_function, suggested_sample, filename, label_x, label_y, color_by_step) 62 63 ---> 64 model.plot_density(bounds[0], alpha=.5) 65 66 plt.plot(x_grid, m, 'k-',lw=1,alpha = 0.6)

AttributeError: 'GPRegression' object has no attribute 'plot_density'

can anyone tell what is wrong with the code below?

domain = [{'name': 'var_1', 'type': 'continuous', 'domain': (-5,4)}] myBopt_1d = BayesianOptimization(f=obj_func, domain=domain) myBopt_1d.run_optimization(max_iter=5) myBopt_1d.plot_acquisition()

Sherif-elsoudy commented 2 years ago

Help us please, the same error here

Sherif-elsoudy commented 2 years ago

help please

jtdimasaka commented 1 year ago

I had a same error, and successfully fixed as follows. This problem would be caused by the change of matplotlib function _process_unit_info(). For me, downgrading matplotlib to 3.1.3 ( pip install matplotlib==3.1.3) works.

Hi, just in case anyone is still looking for ways to resolve this. I tried this suggestion of using matplotlib 3.1.3, and it worked! Here are the steps I did in my Jupyter. My computer has Python 3.9 and I think matplotlib 3.1.3 needs Python 3.6.

  1. Create a new environment with python 3.6 in it. (this helped)
  2. Activate this new environment
  3. I installed a jupyterlab for this new environment (jupyter notebook also works I guess)
  4. I installed all the packages again like GPyOpt, numpy and pandas for my own use.
  5. To check if it has Python 3.6, run a cell with the following:

import sys print(sys.version)

I finally have the "opt.plot_acquisition()" working!