RunTimeError when searching for hyperparameters in RandomizedSearchCV | そう備忘録

RunTimeError when searching for hyperparameters in RandomizedSearchCV

RandomizedSearchCV

When I used RandomizedSearchCV to search for the best hyperparameters for Deep Neural Network, the following error message was displayed and a RunTimeError for Cannot Clone object was raised.

RuntimeError: Cannot clone object <tensorflow.python.keras.wrappers.scikit_learn.KerasRegressor object at 0x000001CEEFBA8550>, as the constructor either does not set or modifies parameter learning_rate
RunTimeError

Environment

The environment in which the error occurred is as follows.

OS

Windows 10 Home(64 Bit)

Anacond

conda 4.10.3

Python

 3.8.5

Keras

Keras 2.4.3

Keras-Applications 1.0.8

Keras-Preprocessing 1.1.2

scikit-learn

 Ver 0.24.2

numpy

 1.20.3

How

Some articles said that it was a bug in scikit-learn and that downgrading the version to 0.21.2 would fix it, but it did not.

Fixed the _search.py file in the Python sklearn library.

I think the location of the file depends on the environment, but since I am using Anaconda, I modified the file in the following path.

C:\Users\User Name\Anaconda3\Lib\site-packages\sklearn\model_selection\_search.py

Lines 876-877 have been revised as follows.

Before
self.best_estimator_ = clone(clone(base_estimator).set_params(
**self.best_params_))
    ↓
After
self.best_estimator_ = clone(base_estimator).set_params(
**self.best_params_)
sklearn _search.py Rev

It seems that RunTimeError was caused by the fact that the error checking was done more strictly.

In addition, I think this fix is only a remedy, but for now, RunTimeError has been resolved.

This is the end of this article.

Finally.

I hope this article will be useful to someone somewhere.

souichirou kikuchi

I'm Japanese. A reminder to remember what I've done. I'm blogging in the hope that it will be helpful to others who want to do similar things. I mainly write blogs about LEGO, AWS (Amazon Web Services), WordPress, Deep Learning and Raspberry Pi. At work, I'm working on installing collaborative robots and IoT in factories. I passed the JDLA (Japan Deep Learning Association) Deep Learning for GENERAL in July 2019. If you have any questions, please leave them in the comments at the bottom of the article.

comment

Name, Email, and Website are optional.
and, your Email address will not be published.