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）
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.
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_)
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.