2014-01-26 45 views
0

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

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

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

谢谢!从RFECV文档字符串

回答

3

直:

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_,然后提交补丁程序,以使其适用于其他型号。

+0

谢谢!桑吉塔 – Sangeeta