RunTimeError when searching for hyperparameters in RandomizedSearchCV
Contents
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
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_)
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.
Recent Comments