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

RunTimeError when searching for hyperparameters in 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


The environment in which the error occurred is as follows.


Windows 10 Home(64 Bit)


conda 4.10.3




Keras 2.4.3

Keras-Applications 1.0.8

Keras-Preprocessing 1.1.2


 Ver 0.24.2




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 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\

Lines 876-877 have been revised as follows.

self.best_estimator_ = clone(clone(base_estimator).set_params(
self.best_estimator_ = clone(base_estimator).set_params(
sklearn 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.


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.


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