xgboost的绘图API说明:
xgboost.plot_importance(booster, ax=None, height=0.2, xlim=None, ylim=None, title='Feature importance', xlabel='F score', ylabel='Features', importance_type='weight', max_num_features=None, grid=True, **kwargs)¶
根据拟合的决策树来确定特征重要性。
参数:
booster (Booster, XGBModel or dict) – Booster or XGBModel instance, or dict taken by Booster.get_fscore()
...
max_num_features (int, default None) – Maximum number of top features displayed on plot. If None, all features will be displayed.
在我的实现中,然而运行:
booster_ = XGBClassifier(learning_rate=0.1, max_depth=3, n_estimators=100,
silent=False, objective='binary:logistic', nthread=-1,
gamma=0, min_child_weight=1, max_delta_step=0, subsample=1,
colsample_bytree=1, colsample_bylevel=1, reg_alpha=0,
reg_lambda=1, scale_pos_weight=1, base_score=0.5, seed=0)
booster_.fit(X_train, y_train)
from xgboost import plot_importance
plot_importance(booster_, max_num_features=10)
返回:
AttributeError: Unknown property max_num_features
在没有使用参数
max_num_features
的情况下运行,图形正确显示了整个特征集(在我的情况下是庞大的,约10k个特征)。有什么想法吗?提前致谢。
详细信息:
> python -V
Python 2.7.12 :: Anaconda custom (x86_64)
> pip freeze | grep xgboost
xgboost==0.4a30