AllAbtPython
AllAbtPython

Reputation: 53

error while performing RFECV through SVR The classifier does not expose "coef_" or "feature_importances_" attributes

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR


housing = pd.read_csv('boston.csv')


x = housing.iloc[:, 0:13].values
y = housing.iloc[:, 13:14].values
y = np.ravel(y)


from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size =   0.33, random_state = 0)
y_train = np.ravel(y_train)


regressor = SVR(kernel = 'poly', degree=2)
regressor.fit(x_train, y_train)

rfecv = RFECV(estimator = regressor, cv=5, scoring='accuracy')

After executing above line (i.e. rfecv) I get the following error:

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

What am I doing wrong ???

Upvotes: 1

Views: 298

Answers (1)

PV8
PV8

Reputation: 6270

You need to fit it afterwards, change it to:

regressor = SVR(kernel = 'poly', degree=2)


rfecv = RFECV(estimator = regressor, cv=5, scoring='accuracy')
rfecv = rfec.fit(x_train, y_train)

Upvotes: 0

Related Questions