【问题标题】:How to use plot_importance function with MultiOutputRegressor?如何将 plot_importance 函数与 MultiOutputRegressor 一起使用?
【发布时间】:2020-06-23 05:10:46
【问题描述】:

我使用代码打击来获得多输出。

但是当我想绘制重要性时,我收到了错误消息。

"ValueError: 树必须是 Booster、XGBModel 或 dict 实例"

如何解决这个问题? 或者有没有其他方法可以获取特征重要性?

import numpy as np
import xgboost as xgb
from xgboost import plot_importance

X = np.array([[0,1,2,3,4],[2,3,4,5,6],[3,4,5,6,7]])
y = np.array([[2,3,4],[3,4,5],[4,5,6]])

model_ = MultiOutputRegressor(xgb.XGBRegressor(objective='reg:linear',n_jobs=-1))
model_.fit(X, y)
pred = model_.predict(X)

fig,ax = plt.subplots(figsize=(15,15))
plot_importance(model_,height=0.5,ax=ax,max_num_features=3)
plt.show()

【问题讨论】:

    标签: machine-learning xgboost


    【解决方案1】:

    我找到了解决办法。

    fig,ax = plt.subplots(ncols=3,figsize=(15,6))
    plot_importance(model.estimators_[0],height=0.5,ax=ax[0],max_num_features=20)
    plot_importance(model.estimators_[1],height=0.5,ax=ax[1],max_num_features=20)
    plot_importance(model.estimators_[2],height=0.5,ax=ax[2],max_num_features=20)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 2019-11-21
      • 2021-10-11
      • 2020-10-26
      相关资源
      最近更新 更多