Getting number of arguments error with scikit rfe ( Python, Scikit Learn )

Problem :
( Scroll to solution )

I am learning machine learning and came across this error. I think it is an issue with my local setup.

# Importing RFE and LinearRegression
from sklearn.feature_selection import RFE
from sklearn.linear_model import LinearRegression

# Running RFE with the output number of the variable equal to 10
lm = LinearRegression(), y_train)

rfe = RFE(lm, 10)             # running RFE
rfe =, y_train)

I get the following error when I run the cell on jupyter

TypeError                                 Traceback (most recent call last)
~AppDataLocalTemp/ipykernel_3420/ in <module>
      3, y_train)
----> 5 rfe = RFE(lm, 10)             # running RFE
      6 rfe =, y_train)

TypeError: __init__() takes 2 positional arguments but 3 were given

The above code seems to be working for others. Any help would be appreciated.


As you can see in the init method of RFE class ( you can only pass two positional arguments (self + estimator).
According to python docs (
Parameters after “*” or “*identifier” are keyword-only parameters and may only be passed used keyword arguments.

In your case, you should type:

rfe = RFE(lm, n_features_to_select=10)

Read more here: Source link