简体   繁体   English

使用adaboost在sklearn中的功能重要性

[英]Feature importance in sklearn using adaboost

I am sing python library sklearn. 我正在唱歌python库sklearn。 I am using adaboost classifier and want to identify which features are most important in classification. 我正在使用adaboost分类器,希望确定分类中最重要的功能。 Following is my code: 以下是我的代码:

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_

I am getting following error: 我收到以下错误:

 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_'

Does anyone have any idea about it, and how to correct it. 是否有人对此有任何想法,以及如何纠正它。

Thanks!! 谢谢!!

Straight from the docstring of RFECV : 直接来自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.

In other words, RFE is currently only implemented for linear models. 换句话说,RFE当前仅用于线性模型。 You could make it work for other models by changing it to use feature_importances_ instead of coef_ and submit a patch. 您可以通过将其更改为使用feature_importances_而不是coef_并提交补丁来使其适用于其他模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在sklearn中使用DictVectorizer后获得分类特征的重要性 - How to get importance of categorical feature after using DictVectorizer in sklearn 使用 sklearn2pmml 时如何获取 feature_importance - How to Get feature_importance when using sklearn2pmml 在RandomForestRegressor sklearn中绘制要素重要性 - Plot feature importance in RandomForestRegressor sklearn 如何在 sklearn 的 RandomForest 中计算特征重要性? - How Feature Importance is calculated in sklearn's RandomForest? 使用 lightgbm 的特征重要性 - Feature importance using lightgbm 从Sklearn管道中提取具有特征名称的特征重要性 - Extracting Feature Importance with Feature Names from a Sklearn Pipeline 使用 SelectKBest 在 Python 中的特征重要性 - Feature importance in Python using SelectKBest 如何计算sklearn中每个交叉验证模型中的特征重要性 - How to calculate feature importance in each models of cross validation in sklearn 具有一个热编码特征的Auto-Sklearn中的特征和特征重要性 - Features and Feature importance in Auto-Sklearn with One Hot Encoded Features RandomForestClassifier - 尝试识别 sklearn 中的特征重要性的奇怪错误? - RandomForestClassifier - Odd error with trying to identify feature importance in sklearn?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM