Search code examples
pythontensorflowmachine-learning

How do I import KerasRegressor in Google Colab?


I'm using Google colab, and have a problem importing KerasRegressor.

I run:

from tensorflow.keras.wrappers.scikit_learn import KerasRegressor

and get the following error:

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

In some forums, I found people solving the issue with the "scikeras", but I am having problems with this on colab.

How to resolve this?


Solution

  • In Google Colab try:

    !pip install scikeras
    from scikeras.wrappers import KerasRegressor
    

    This should get you up and running with the current libraries on Google Colab (as of September 2024).

    It looks like the wrappers module may no longer be availabele in tensorflow.