user3104352
user3104352

Reputation: 1130

RuntimeError: The classifier does not expose "coef_" or "feature_importances_" attributes

In my code, it throws a runtime error. Here, I am trying to fit RFE for regression data.

from sklearn.feature_selection import RFE
from sklearn.svm import SVR           
from sklearn.feature_selection import SelectKBest
from sklearn.preprocessing import *

scaler = StandardScaler().fit(trainFeatures)
xscaled = scaler.transform(trainFeatures)
estimator = SVR()
selector = RFE(estimator, dimension, step=1)
selector = selector.fit(xscaled, trainOutput.ravel())
selectedFeatures = selector.transform(xscaled)

Upvotes: 1

Views: 1633

Answers (1)

vpekar
vpekar

Reputation: 3355

As per this link, RFE only works with SVR when the kernel is linear.

By default, it is "rbf", so do:

estimator = SVR(kernel="linear")

Upvotes: 1

Related Questions