【问题标题】:xgboost plot importance figure sizexgboost 绘图重要性图形大小
【发布时间】:2017-02-26 04:07:17
【问题描述】:

如何更改xgboost的绘图重要性函数的图形大小?

尝试传递 figsize=(10,20) 失败,但出现未知属性。

【问题讨论】:

标签: python matplotlib scikit-learn xgboost


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您还可以使用以下方法设置图形大小:

    from xgboost import plot_importance
    import matplotlib.pyplot as plt
    
    plt.rcParams["figure.figsize"] = (14, 7)
    plot_importance(booster=booster)
    

    【讨论】:

      【解决方案3】:

      仅将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) 以放大或缩小图像尺寸

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-16
        • 1970-01-01
        • 2019-01-25
        • 2017-02-22
        • 2020-11-13
        • 1970-01-01
        • 2021-02-26
        • 1970-01-01
        相关资源
        最近更新 更多