xgboost 有 feature_importances_ 吗?

Does xgboost have feature_importances_?

我正在通过它的 scikit-learn-style Python 接口调用 xgboost:

model = xgboost.XGBRegressor() 
%time model.fit(trainX, trainY)
testY = model.predict(testX)

一些 sklearn 模型通过属性 feature_importances 告诉您它们赋予特征的重要性。对于 XGBRegressor:

这似乎不存在
model.feature_importances_
AttributeError   Traceback (most recent call last)
<ipython-input-36-fbaa36f9f167> in <module>()
----> 1 model.feature_importances_

AttributeError: 'XGBRegressor' object has no attribute 'feature_importances_'

奇怪的是:对于我的合作者,属性 feature_importances_ 在那里!可能是什么问题?

这些是我的版本:

In [2]: xgboost.__version__
Out[2]: '0.6'

In [4]: sklearn.__version__
Out[4]: '0.18.1'

...和来自 github 的 xgboost C++ 库,提交 ef8d92fc52c674c44b824949388e72175f72e4d1.

你是怎么安装xgboost的?您是否按照文档中的描述从 github 克隆包后构建了包?

http://xgboost.readthedocs.io/en/latest/build.html

如本回答所示:

pip 安装和 xgboost 似乎总是有问题。从您的构建中构建和安装它似乎有所帮助。

也许这对你有用。

xgb.plot_importance(bst)

这是 link:plot