Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import KerasClassifier now?

How to import KerasClassifier for use with Gridsearch?

The following

from tensorflow.keras.layers.wrappers.scikit_learn import KerasClassifier

Used to work, but now returns:

ModuleNotFoundError: No module named 'tensorflow.keras.wrappers'

I understand there have been several changes to Tensorflow and Keras. I would prefer not to just install an older version, so I'm working to figure out how to use this going foward.

Reading elsewhere, it sounds like this may have been deprecated and replaced by SciKeras, but it sounds like that may also require a lot of other changes to the code. I have many instances of doing fits and using the history.

Is making that switch the best way given a limited timeframe? Should I just go to an older version?

Currently running tf version 2.13.0 and keras version 2.13.1 and I've recently updated both so don't think it's a version mismatch item. It may be I just need to take both back to 2.12.

like image 253
Tom S Avatar asked Sep 07 '25 17:09

Tom S


1 Answers

The proposed changes in adriangb.com/scikeras worked for me. I could use GridSearch. Also had to first install scikeras:

pip install scikeras
like image 170
Emilia G Avatar answered Sep 10 '25 07:09

Emilia G