'How to save a pycaret plot?

I'm trying to save a pycaret plot but only get a blank file:

plt.figure(figsize = (18,9))
plot_model(pycaret_xgboost, 'auc')
plt.savefig('ROC_xboost.svg')


Solution 1:[1]

In PyCaret 2.0 you can pass save parameter inside plot_model.

For example:

plot_model(model, plot = 'AUC', save=True)

This will save AUC.png in your current working directory.

Solution 2:[2]

Update PyCaret to 2.0

Update pycaret to 2.0 (pip install pycaret==2.0). A new parameter save has been added in plot_model() function. When save is set to True, a png / html file depending on the type of plot is saved in current working directory. Names of each plot is pre-defined.

Solution 3:[3]

@maria_g shared an correct reference.As in the answer the person is using only pyplot to both plot and save the graph.

Solution 4:[4]

Attached is an example of how vector plots (pdf, svg, eps) can be derived from pycaret models, using yellowbrick. It has been tested with googlecolab and pycaret 2.3.4.

#---- data
from pycaret.datasets import get_data
dataset = get_data('diamond')

#---- model pycaret
from pycaret.regression import *
exp_reg101 = setup(data = dataset, target = 'Price', session_id=123, 
                   remove_multicollinearity = True, multicollinearity_threshold = 0.95) 

lightgbm = create_model('lightgbm')

#---- plot
from yellowbrick.regressor import ResidualsPlot

X_train, X_test, y_train, y_test = get_config('X_train'), get_config('X_test'), get_config('y_train'), get_config('y_test')

visualizer = ResidualsPlot(lightgbm) # regression model
visualizer.fit(X_train, y_train) # Fit the training data to the visualizer
visualizer.score(X_test, y_test) # Evaluate the model on the test data
visualizer.poof(outpath="ResidualsPlot.pdf") # VECTOR .pdf .eps .svg, RASTER .png .jpg .tif
#visualizer.poof()  # Finalize and render the figure

#---- file extensions supported
import matplotlib.pyplot as plt
plt.figure().canvas.get_supported_filetypes()

Solution 5:[5]

You are using pyplot and pycaret interchangeably. I suggest you to read the documentation thoroughly. The reason " ROC_xboost.svg" is blank because you didn't plot anything using pyplot. You clearly used pycaret's "plotmodel" to just plot it. Pycaret provides "save_model()" to save the created model though it wont save the plot. Please refer to https://pycaret.org/plot-model/, https://pycaret.org/save-model/ . Plot your model using pyplot.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Greenonline
Solution 3 Foreverlearner
Solution 4
Solution 5