【问题标题】:Feature importance in sklearn using adaboost使用 adaboost 在 sklearn 中的特征重要性
【发布时间】:2014-02-17 06:52:06
【问题描述】:

我正在唱歌 python 库 sklearn。我正在使用 adaboost 分类器,并想确定哪些特征在分类中最重要。以下是我的代码:

ada =    AdaBoostClassifier(n_estimators=100)
selector = RFECV(ada, step=1, cv=5) 
selector = selector.fit(np.asarray(total_data), np.asarray(target))
selector.support_
print "featue ranking", selector.ranking_

我收到以下错误:

 selector = selector.fit(np.asarray(total_data), np.asarray(target))
  File "C:\Python27\lib\site-packages\sklearn\feature_selection\rfe.py", line 336, in fit
    ranking_ = rfe.fit(X_train, y_train).ranking_
  File "C:\Python27\lib\site-packages\sklearn\feature_selection\rfe.py", line 148, in fit
    if estimator.coef_.ndim > 1:
AttributeError: 'AdaBoostClassifier' object has no attribute 'coef_'

有没有人对此有任何想法,以及如何纠正它。

谢谢!!

【问题讨论】:

    标签: python classification scikit-learn


    【解决方案1】:

    直接来自RFECV的文档字符串:

    Parameters
    ----------
    estimator : object
        A supervised learning estimator with a `fit` method that updates a
        `coef_` attribute that holds the fitted parameters. Important features
        must correspond to high absolute values in the `coef_` array.
    
        For instance, this is the case for most supervised learning
        algorithms such as Support Vector Classifiers and Generalized
        Linear Models from the `svm` and `linear_model` modules.
    

    换句话说,RFE 目前仅针对线性模型实施。您可以通过将其更改为使用 feature_importances_ 而不是 coef_ 并提交补丁来使其适用于其他模型。

    【讨论】:

      猜你喜欢
      • 2021-09-02
      • 2019-11-05
      • 2021-08-22
      • 2019-05-30
      • 2019-08-10
      • 2014-10-28
      • 2012-04-20
      • 2016-12-11
      • 1970-01-01
      相关资源
      最近更新 更多