我该如何改变xgboost的plot importance函数的图像大小?
尝试将figsize=(10,20)传递给该函数会导致未知属性的异常。
我该如何改变xgboost的plot importance函数的图像大小?
尝试将figsize=(10,20)传递给该函数会导致未知属性的异常。
您可以在plot_importance()
函数的ax
参数中传递一个轴。例如,使用以下包装器:
def my_plot_importance(booster, figsize, **kwargs):
from matplotlib import pyplot as plt
from xgboost import plot_importance
fig, ax = plt.subplots(1,1,figsize=figsize)
return plot_importance(booster=booster, ax=ax, **kwargs)
使用my_plot_importance()
替代plot_importance()
您还可以使用以下代码设置图形大小:
from xgboost import plot_importance
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (14, 7)
plot_importance(booster=booster)
只需在您的代码中添加plt.rcParams["figure.figsize"] = (20,50)
例如:
from xgboost import plot_importance
plt.figure(figsize=(40,20))
plot_importance(model,max_num_features=100)
plt.rcParams["figure.figsize"] = (20,100)
plt.show()
调整 (20,100) 以放大或缩小图像大小