【发布时间】:2016-03-16 06:23:08
【问题描述】:
我正在使用递归特征估计 (RFE) 进行特征选择。其工作原理是迭代地采用 SVM 分类器等估计器,将其拟合到数据中,然后移除具有最低权重(系数)的特征。
我能够将其与数据相匹配并执行特征选择。但是,我想从 RFE 中恢复每个特征的学习权重。
我使用以下代码来初始化一个分类器对象和一个 RFE 对象,并将它们与数据相匹配。
svc = SVC(C=1, kernel="linear")
rfe = RFE(estimator=svc, n_features_to_select=300, step=0.1)
rfe.fit(all_training, training_labels)
然后我尝试打印系数
print ('coefficients',svc.coef_)
并接收:
AttributeError: 'RFE' object has no attribute 'dual_coef_'
根据sklearn documentation,分类器对象应该有这个属性:
coef_ : array, shape = [n_class-1, n_features]
Weights assigned to the features (coefficients in the primal problem). This is only
available in the case of a linear kernel.
coef_ is a readonly property derived from dual_coef_ and support_vectors_.
我使用的是线性内核,所以这不是问题。
谁能解释为什么我无法恢复系数?有没有办法解决这个问题?
【问题讨论】:
标签: python machine-learning scikit-learn feature-selection rfe