Stepping into RFE and getting 'DataFrame object is not callable" error

ajbentley

I'm trying to use RFE for the first time and banging my head against a "DataFrame object is not callable" error.

Here is my code

X, y = df5(n_samples=875, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
selector = RFE(LinearRegression, step=1, cv=5)
selector = selector.fit(X, y)
df5([ True,  True,  True,  True,  True,
        False, False, False, False, False], dtype=bool)

selector.ranking_
df5([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])

I'm looking at a dataset with 49 Features and the output I'm looking for is which of these features should be kept and which kicked out.

Bonus points if anyone can help me figure out how to get this into an RFECV!

sergzach

If you want select columns first figure out the information about your dataframe then select required features.

# the next 2 lines is to initialize DataFrame object (just for the example)
>>> from pandas import DataFrame
>>> df = DataFrame.from_dict({'one': range(10), 'two': range(10, 0, -1), 'three': [3 for x in range(10)]})

# now figure out what columns you df has:
>>> df.head()
   one  three  two
0    0      3   10
1    1      3    9
2    2      3    8
3    3      3    7
4    4      3    6
5    5      3    5
6    6      3    4
7    7      3    3
8    8      3    2
9    9      3    1

# Now you can slice specific columns (features in your case):
>>> df[['one', 'two']]
   one  two
0    0   10
1    1    9
2    2    8
3    3    7
4    4    6
5    5    5
6    6    4
7    7    3
8    8    2
9    9    1

Are your feature names numerical? I'm not sure. Check it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Related Related

HotTag

Archive