mljar / mljar-supervised

Python package for AutoML on Tabular Data with Feature Engineering, Hyper-Parameters Tuning, Explanations and Automatic Documentation
https://mljar.com
MIT License
3.06k stars 409 forks source link

Plots not showing in Jupyter/.ipynb #785

Open Dorota-D opened 2 weeks ago

Dorota-D commented 2 weeks ago

Environment:

I wanted to plot the optimized ML model fits in my jupyter notebook file, but the plots did not show up - only the text line, e.g., <Axes: xlabel='total_bill', ylabel='tip'>. Using %matplotlib inline did not help. I can still save the plots as JPG, but that is not the point. I found that the problem appears when I activate AutoML. This conflict appears even in the most basic example:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
tips.head()
sns.scatterplot(data=tips, x="total_bill", y="tip")

Here, the plot shows up. After adding a cell with AutoML, the plot "disappears".

from supervised import AutoML
sns.scatterplot(data=tips, x="total_bill", y="tip")

How can I resolve this?

pplonski commented 2 weeks ago

Hi @Dorota-D,

Thank you for reporting the issue. Looks like AutoML overwrites the matplotlib backend.

For quick fix please execute:

import matplotlib
matplotlib.use('WebAgg') 

you can check list of available backends here https://matplotlib.org/stable/users/explain/figure/backends.html#interactive-backends

Please let me know if it works for you.

Dorota-D commented 2 weeks ago

Hi Piotr,

Thanks for your quick reply. No, unfortunately not, the problem remains and "WebAgg" also completely disables the plot even before AutoML loads :(

Dorota-D commented 2 weeks ago

Another thing - I've added another cell at the end:

fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()

I got the following error message: UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown

pplonski commented 2 weeks ago

One more try:

matplotlib.use('module://matplotlib_inline.backend_inline')
Dorota-D commented 2 weeks ago

Works! Thank you!

pplonski commented 2 weeks ago

Great! May I ask what is your use case for AutoML? I will reopen the issue, because it should be fixed in the package.

Dorota-D commented 2 weeks ago

Research :) Our group developed simple models in Weka, but we'd like to integrate ML with our other scripts. scikit is ok, but we feel we need something robust and quick. So, now we're testing AutoML.