1

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')
korakot
  • 37,818
  • 16
  • 123
  • 144

6 Answers6

3

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
PyCaret
  • 94
  • 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.

Greenonline
  • 1,330
  • 8
  • 23
  • 31
PyCaret
  • 94
  • 2
0

As you are trying to save the figure as svg file,this problem may occur. Here is an answer on StackOverflow that may help you

maria_g
  • 130
  • 1
  • 6
0

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

0

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()
-2

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.