RandomizedSearchCV doesn't stop running

I'm trying to optimize the hyperparameters of my model using RandomizedSearchCV. However, it doesn't stop running even if I define few iterations. Someone could help me? The code I'm using is presented below:

def build_classifier(optimizer, units, alpha, l1):
    model = tf.keras.Sequential()
    model.add(tf.keras.layers.LSTM(units, kernel_regularizer = regularizers.l1(l1 = l1), input_shape= (None, n_features), return_sequences = True))
    model.add(tf.keras.layers.LSTM(units, kernel_regularizer = regularizers.l1(l1 = l1), return_sequences = True))
    model.add(tf.keras.layers.LSTM(units, kernel_regularizer = regularizers.l1(l1 = l1), return_sequences = False))
    model.add(tf.keras.layers.Dense(5))

    model.compile(optimizer = optimizer, loss = 'mae')
    return model

from keras.wrappers.scikit_learn import KerasRegressor
parameters ={'optimizer':['adam','rmsprop','SGD'],
            'units':[4,8,16,32,64,128],
            'alpha':[0.1,0.2,0.3,0.4,0.5],
            'l1':[0.00001,0.0001,0.001,0.01,0.1],
            'epochs':[2,5]}

classifier = KerasRegressor(build_fn = build_classifier)

from sklearn.model_selection import RandomizedSearchCV
random_search = RandomizedSearchCV(estimator = classifier, param_distributions = parameters, n_iter = 1, n_jobs = 1, cv = 5, scoring = 'neg_mean_absolute_error')

y_hyperparameters = np.reshape(y_hyperparameters, (y_hyperparameters.shape[0], n_features))

random_search.fit(X_hyperparameters, y_hyperparameters, verbose = 1, batch_size = 1, validation_data = (test_X_hyperparameters, test_y_hyperparameters), shuffle = False)

print('Random Best score:', random_search.best_score_)
print('Random Best params:', random_search.best_params_)

Topic hyperparameter-tuning python

Category Data Science


One possible cause of errors is the mixing and matching of completely different algorithms: regressors, classifiers, and sequence models (i.e., LSTM). You import a regressor, you name it a classifier, and the actual model is an LSTM.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.