Is this a bug, or am I doing it wrong?
There’s an issue with PyCaret plot_model() function. It does open the specified plot, but when closing the plot by clicking on the “X” mark or Ctrl+W the script crashes with following output:
Traceback (most recent call last):
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/./inverter_ML_regression_2F_test.py", line 69, in <module>
experiment1.plot_model(tuned_gbr, plot = 'error') # Prediction Error Plot
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/pycaret/regression/oop.py", line 1946, in plot_model
return super().plot_model(
^^^^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/pycaret/internal/pycaret_experiment/tabular_experiment.py", line 2045, in plot_model
return self._plot_model(
^^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/pycaret/internal/pycaret_experiment/tabular_experiment.py", line 1913, in _plot_model
ret = locals()[plot]()
^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/pycaret/internal/pycaret_experiment/tabular_experiment.py", line 1227, in error
return show_yellowbrick_plot(
^^^^^^^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/pycaret/internal/plots/yellowbrick.py", line 115, in show_yellowbrick_plot
visualizer.show(clear_figure=True)
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib/python3.11/site-packages/yellowbrick/base.py", line 249, in show
self.fig.clear()
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/figure.py", line 3148, in clear
super().clear(keep_observers=keep_observers)
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/figure.py", line 978, in clear
self.delaxes(ax) # Remove ax from self._axstack.
^^^^^^^^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/figure.py", line 945, in delaxes
self._axobservers.process("_axes_change_event", self)
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/cbook/__init__.py", line 319, in process
self.exception_handler(exc)
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/cbook/__init__.py", line 103, in _exception_printer
raise exc
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/cbook/__init__.py", line 314, in process
func(*args, **kwargs)
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/figure.py", line 3253, in <lambda>
self._axobservers.connect("_axes_change_event", lambda arg: func(arg))
^^^^^^^^^
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/backend_bases.py", line 2848, in notify_axes_change
self.toolbar.update()
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/backend_bases.py", line 3382, in update
self.set_history_buttons()
File "/home/boris/Documents/EDU/AI-ML_examples/inverter_virtualenv/lib64/python3.11/site-packages/matplotlib/backends/_backend_tk.py", line 892, in set_history_buttons
self._buttons['Back']['state'] = state_map[can_back]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/usr/lib64/python3.11/tkinter/__init__.py", line 1732, in __setitem__
self.configure({key: value})
File "/usr/lib64/python3.11/tkinter/__init__.py", line 1721, in configure
return self._configure('configure', cnf, kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/tkinter/__init__.py", line 1711, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!navigationtoolbar2tk.!button2"
Only plot that doesn’t crash when closed is the ‘pipeline’ plot. All other plot types are crashing on close.
PyCaret version:
(inverter_virtualenv) boris@E5440-DELL:~/Documents/EDU/AI-ML_examples/inverter_virtualenv$ pip list | grep pycaret
pycaret 3.3.2
(inverter_virtualenv) boris@E5440-DELL:~/Documents/EDU/AI-ML_examples/inverter_virtualenv$ pip list | grep yellowbrick
yellowbrick 1.5
(inverter_virtualenv) boris@E5440-DELL:~/Documents/EDU/AI-ML_examples/inverter_virtualenv$ pip list | grep matplotlib
matplotlib 3.7.5
matplotlib-inline 0.1.7
This is my code sample:
from pycaret.regression import *
experiment1 = RegressionExperiment()
experiment1.setup(X_train, target="delay")
print(experiment1)
top3_best = experiment1.compare_models(exclude=['lightgbm'], n_select=3)
print(top3_best)
initial_et = experiment1.create_model('et')
initial_rf = experiment1.create_model('rf')
initial_gbr = experiment1.create_model('gbr')
print(initial_et)
print(initial_rf)
print(initial_gbr)
#tuned_et = experiment1.tune_model(initial_et)
#tuned_rf = experiment1.tune_model(initial_rf)
tuned_gbr = experiment1.tune_model(initial_gbr)
#print(tuned_et)
#print(tuned_rf)
print(tuned_gbr)
experiment1.plot_model(tuned_gbr, plot = 'pipeline') # Schematic drawing of the preprocessing pipeline
#experiment1.plot_model(tuned_gbr, plot = 'residuals') # Residuals Plot
experiment1.plot_model(tuned_gbr, plot = 'error') # Prediction Error Plot
#experiment1.plot_model(tuned_gbr, plot = 'cooks') # Cooks Distance Plot
#experiment1.plot_model(tuned_gbr, plot = 'rfe') # Recursive Feat. Selection
experiment1.plot_model(tuned_gbr, plot = 'learning') # Learning Curve
#experiment1.plot_model(tuned_gbr, plot = 'vc') # Validation Curve
#experiment1.plot_model(tuned_gbr, plot = 'manifold') # Manifold Learning
experiment1.plot_model(tuned_gbr, plot = 'feature') # Feature Importance