XGBoost绘制特征重要性图的尺寸大小

11

我该如何改变xgboost的plot importance函数的图像大小?

尝试将figsize=(10,20)传递给该函数会导致未知属性的异常。


最终,我基于 https://github.com/ViennaKaggle/allstate-claims-severity/blob/master/chris/01_Analysis.ipynb 进行了自己的开发。 - Georg Heiler
3个回答

29

您可以在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()


13

您还可以使用以下代码设置图形大小:

from xgboost import plot_importance
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = (14, 7)
plot_importance(booster=booster)

2

只需在您的代码中添加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) 以放大或缩小图像大小


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接