OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't import KerassRegressor

  • Thread starter Thread starter Mahesh Maskey
  • Start date Start date
M

Mahesh Maskey

Guest
I have been trying to import KerasRegressor hyper-parameterization of the LSTM time series model to improve its performance in both HPC Linux** and **Windows. For this, I installed tensorflow using pip and tried to import KerasRegressor as follows without success.

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

Unfortunately, it displays Traceback as follows

Code:
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[67], line 1
1 from tensorflow.keras.wrappers.scikit_learn import KerasRegressor
ModuleNotFoundError: No module named 'tensorflow.keras.wrappers'

Later, I learned that it had been migrated, so I tried the second option as follows:

Code:
`from scikeras.wrappers import KerasRegressor`
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[68], line 1
1 from scikeras.wrappers import KerasRegressor
File /path/to/conda_envoronment/lib/python3.10/site-packages/scikeras/wrappers.py:35
33 from scikeras.utils import loss_name, metric_name
34 from scikeras.utils.random_state import tensorflow_random_state
35 from scikeras.utils.transformers import ClassifierLabelEncoder, RegressorTargetEncoder
38 class BaseWrapper(BaseEstimator):
39     """Implementation of the scikit-learn classifier API for Keras.
40 
41     Below are a list of SciKeras specific parameters. For details on other parameters,
(...)
124         The number of features seen during `fit`.
125     """
File /project/swmru_apex/myspatial/lib/python3.10/site-packages/scikeras/utils/transformers.py:12
10 from sklearn.base import BaseEstimator, TransformerMixin
11 from sklearn.exceptions import NotFittedError
12 from sklearn.pipeline import make_pipeline
13 from sklearn.preprocessing import FunctionTransformer, OneHotEncoder, OrdinalEncoder
14 from sklearn.utils.multiclass import type_of_target
File /project/swmru_apex/myspatial/lib/python3.10/site-packages/sklearn/pipeline.py:19
16 import numpy as np
17 from scipy import sparse
19 from .base import TransformerMixin, _fit_context, clone
20 from .exceptions import NotFittedError
21 from .preprocessing import FunctionTransformer
ImportError: cannot import name '_fit_context' from 'sklearn.base' (/path/to/conda_environment/lib/python3.10/site-packages/sklearn/base.py)

I really appreciate is there any other ways to hyper parameterize the LSTM time series model if there is no solution to it. If so, how it could be implemented in k-fold cross validation as well. Sooner response is greatly appreciated.

Thanks

I am trying to hyper-parameterize deep learning model as well as cross validate.
<p>I have been trying to import KerasRegressor hyper-parameterization of the <code>LSTM</code> time series model to improve its performance in both <strong><code>HPC Linux** and **</code>Windows</strong>. For this, I installed <code>tensorflow</code> using <code>pip</code> and tried to import <code>KerasRegressor</code> as follows without success.</p>
<ol>
<li><code>ModuleNotFoundError: No module named 'tensorflow.keras.wrappers'</code></li>
</ol>
<p>Unfortunately, it displays <strong>Traceback</strong> as follows</p>
<pre><code>ModuleNotFoundError Traceback (most recent call last)
Cell In[67], line 1
1 from tensorflow.keras.wrappers.scikit_learn import KerasRegressor
ModuleNotFoundError: No module named 'tensorflow.keras.wrappers'
</code></pre>
<p>Later, I learned that it had been migrated, so I tried the second option as follows:</p>
<pre><code>`from scikeras.wrappers import KerasRegressor`
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[68], line 1
1 from scikeras.wrappers import KerasRegressor
File /path/to/conda_envoronment/lib/python3.10/site-packages/scikeras/wrappers.py:35
33 from scikeras.utils import loss_name, metric_name
34 from scikeras.utils.random_state import tensorflow_random_state
35 from scikeras.utils.transformers import ClassifierLabelEncoder, RegressorTargetEncoder
38 class BaseWrapper(BaseEstimator):
39 """Implementation of the scikit-learn classifier API for Keras.
40
41 Below are a list of SciKeras specific parameters. For details on other parameters,
(...)
124 The number of features seen during `fit`.
125 """
File /project/swmru_apex/myspatial/lib/python3.10/site-packages/scikeras/utils/transformers.py:12
10 from sklearn.base import BaseEstimator, TransformerMixin
11 from sklearn.exceptions import NotFittedError
12 from sklearn.pipeline import make_pipeline
13 from sklearn.preprocessing import FunctionTransformer, OneHotEncoder, OrdinalEncoder
14 from sklearn.utils.multiclass import type_of_target
File /project/swmru_apex/myspatial/lib/python3.10/site-packages/sklearn/pipeline.py:19
16 import numpy as np
17 from scipy import sparse
19 from .base import TransformerMixin, _fit_context, clone
20 from .exceptions import NotFittedError
21 from .preprocessing import FunctionTransformer
ImportError: cannot import name '_fit_context' from 'sklearn.base' (/path/to/conda_environment/lib/python3.10/site-packages/sklearn/base.py)
</code></pre>
<p>I really appreciate is there any other ways to hyper parameterize the LSTM time series model if there is no solution to it. If so, how it could be implemented in k-fold cross validation as well. Sooner response is greatly appreciated.</p>
<p>Thanks</p>
<p>I am trying to hyper-parameterize deep learning model as well as cross validate.</p>
 

Latest posts

Top