I am attempting to use scikit-optimize to tune the hyperparameters of a scikit-learn multi-layer perception regressor (MLPRegressor). However, the problem is that scikit-optimize seems to convert the list of categorical variables into a numpy array, which cause problems because the number of hidden layers and the number of points therein is expressed as a tuple, and numpy does not allow storing tuples in arrays (without declaring them as objects, which I am not sure how to do in this case).
My code is:
from sklearn.neural_network import MLPRegressor
import skopt.space
from skopt import BayesSearchCV
model= MLPRegressor(max_iter=5000)
param_space = {
'hidden_layer_sizes': skopt.space.Categorical([(100,),(50,100,50),(75,50,20)]),
'activation': skopt.space.Categorical(['tanh','relu']),
'solver': skopt.space.Categorical(['adam','lbfgs']),
'alpha': skopt.space.Real(0.0001,1,prior='log-uniform'),
'batch_size': skopt.space.Categorical([64,128,200]), ###
'learning_rate': skopt.space.Categorical(['constant','adaptive'])
}
opt = BayesSearchCV(model, param_space, n_jobs=16, cv=3, verbose=1, scoring='neg_mean_absolute_error')
input_data = get_fingerprint('MACCS',data)
opt.fit(input_data,regr_target)
Then I get this error:
E:\UserPrograms\miniconda3\envs\main\lib\site-packages\skopt\space\transformers.py:169: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. X = np.asarray(X)
Full screenshot below:
Clearly, skopt
is attempting to convert the list given in the categorical variable search space into a numpy array. I have tried setting transform='identity'
in declaring the Categorical space, but that doesn't help.
How do I solve this problem? The github page for scikit-optimize seems to be inactive for quite some time and they are not responding to the issues, so I thought this is the best place to ask this question.
(If you know any other alternative to scikit-optimize that can do this, I will be happy to use that as well!)