1

I want to apply Recursive Feature Elimination (RFE) on a model that is built using Keras models and layers. When I run:

from sklearn.feature_selection import RFE
## building Keras model ... #
rfe = RFE(model, 3)
rfe = rfe.fit(X_train, y_train)

I get following error:

TypeError: Cannot clone object '<keras.models.Sequential object at 0x7f1ab93eb510>' (type <class 'keras.models.Sequential'>): it does not seem to be a scikit-learn estimator as it does not implement a 'get_params' methods.

I tried to clone my Keras model by clone_model(model), but it did not help. Do I have to use sklearn estimator to be able to use RFE?

Shannon
  • 985
  • 3
  • 11
  • 25
  • 2
    Yes. You need to use scikit compliant classes to use the RFE, GridSearch or any other scikit-learn methods like cross_val_score etc. The keras has one wrapper to make a Sequential model to scikit usable, which can be [found here](https://keras.io/scikit-learn-api/) – Vivek Kumar Jan 05 '18 at 08:07
  • @VivekKumar, thanks for providing the link. I will read it. – Shannon Jan 05 '18 at 21:42

0 Answers0