I am using Recursive Feature Estimation (RFE) for feature selection. This works by iteratively taking an estimator such as an SVM classifier, fitting it to the data, and removing the features with the lowest weights (coefficients).
I am able to fit this to the data and perform feature selection. However, I then want to recover the learned weights for each feature from the RFE.
I use the following code to initialise a classifier object and an RFE object, and I fit these to the data.
svc = SVC(C=1, kernel="linear")
rfe = RFE(estimator=svc, n_features_to_select=300, step=0.1)
rfe.fit(all_training, training_labels)
I then try to print the coefficients
print ('coefficients',svc.coef_)
And receive:
AttributeError: 'RFE' object has no attribute 'dual_coef_'
According to sklearn documentation, the classifier object should have this attribute :
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_.
I am using a linear kernel, so that is not the problem.
Can anyone explain why I am unable to recover the coefficients? And is there a way around this?