xgboost 有 feature_importances_ 吗?

cls*_*udt 5 c++ python machine-learning scikit-learn xgboost

我通过 scikit-learn 风格的 Python 接口调用 xgboost:

model = xgboost.XGBRegressor() 
%time model.fit(trainX, trainY)
testY = model.predict(testX)
Run Code Online (Sandbox Code Playgroud)

一些 sklearn 模型通过 attribute 告诉您它们为特征分配的重要性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_'
Run Code Online (Sandbox Code Playgroud)

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

这些是我拥有的版本:

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

In [4]: sklearn.__version__
Out[4]: '0.18.1'
Run Code Online (Sandbox Code Playgroud)

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

小智 2

你是如何安装xgboost的?您是否按照文档中所述从 github 克隆后构建了该包?

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

正如这个答案中所说:

XGBClassifier 的功能重要性

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