【问题标题】:Does xgboost have feature_importances_?xgboost 有 feature_importances_ 吗?
【发布时间】:2017-05-24 17:19:32
【问题描述】:

我正在通过其 scikit-learn 风格的 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

【问题讨论】:

    标签: python c++ machine-learning scikit-learn xgboost


    【解决方案1】:

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

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

    在这个答案中:

    Feature Importance with XGBClassifier

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

    【讨论】:

    • 这就是问题所在,谢谢 - 通过 pip 分发的包似乎已经过时了。
    【解决方案2】:

    这可能对你有用。

    xgb.plot_importance(bst)

    这是链接:plot

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2019-06-12
      • 2020-07-28
      • 1970-01-01
      • 2016-05-17
      • 2019-12-25
      • 1970-01-01
      相关资源
      最近更新 更多