简体   繁体   English

如何保存 pycaret plot?

[英]How to save a pycaret plot?

I'm trying to save a pycaret plot but only get a blank file:我正在尝试保存 pycaret plot 但只得到一个空白文件:

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

Update PyCaret to 2.0将 PyCaret 更新到 2.0

Update pycaret to 2.0 ( pip install pycaret==2.0 ).将 pycaret 更新到 2.0 ( pip install pycaret==2.0 )。 A new parameter save has been added in plot_model() function.plot_model() function 中添加了一个新参数save When save is set to True, a png / html file depending on the type of plot is saved in current working directory.当 save 设置为 True 时,一个 png / html 文件将根据 plot 的类型保存在当前工作目录中。 Names of each plot is pre-defined.每个 plot 的名称是预定义的。

In PyCaret 2.0 you can pass save parameter inside plot_model .在 PyCaret 2.0 中,您可以在plot_model中传递save参数。

For example:例如:

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

This will save AUC.png in your current working directory.这会将 AUC.png 保存在您当前的工作目录中。

As you are trying to save the figure as svg file,this problem may occur.当您尝试将图形保存为 svg 文件时,可能会出现此问题。 Here is an answer on StackOverflow that may help you 是 StackOverflow 上的一个答案,可能会对您有所帮助

@maria_g shared an correct reference.As in the answer the person is using only pyplot to both plot and save the graph. @maria_g 分享了一个正确的参考。正如在答案中,这个人只对 plot 使用 pyplot 并保存图表。

Attached is an example of how vector plots (pdf, svg, eps) can be derived from pycaret models, using yellowbrick.附件是如何使用黄砖从 pycaret 模型导出矢量图(pdf,svg,eps)的示例。 It has been tested with googlecolab and pycaret 2.3.4.它已经用 googlecolab 和 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()

You are using pyplot and pycaret interchangeably.您正在交替使用 pyplot 和 pycaret。 I suggest you to read the documentation thoroughly.我建议您仔细阅读文档。 The reason " ROC_xboost.svg" is blank because you didn't plot anything using pyplot. “ROC_xboost.svg”的原因是空白的,因为您没有使用 pyplot 进行 plot 任何操作。 You clearly used pycaret's "plotmodel" to just plot it.您显然使用了 pycaret 的“plotmodel”来仅 plot 它。 Pycaret provides "save_model()" to save the created model though it wont save the plot. Pycaret 提供“save_model()”来保存创建的 model,尽管它不会保存 plot。 Please refer to https://pycaret.org/plot-model/ , https://pycaret.org/save-model/ .请参考https://pycaret.org/plot-model/https://pycaret.org/save-model/ Plot your model using pyplot. Plot 你的 model 使用 pyplot。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM