我使用代码打击来获得多个输出。
但是当我想显示重要性时,我收到了错误消息。
“ ValueError:树必须是Booster,XGBModel或字典实例”
如何解决此问题?还是有其他方法可以提高功能的重要性?
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()
我找到了解决方案。
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()