Reputation: 115
I am trying to run a grid search for a neural network but I keep getting some weird errors. my algorithm looks like:
parameters={'learning_rate':["constant", "invscaling", "adaptive"],
'hidden_layer_sizes': (156,), 'alpha': [10.0 ** -np.arange(1, 7)],
'activation': ["logistic", "relu", "Tanh"]}
grid= GridSearchCV(MLPClassifier(),parameters, n_jobs=-1, cv=10)
grid.fit(train_x, train_y)
The error message I get is:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I have tried to also use just 1 value wit regards to the activation
and learning_rate
but the problem seem to persist. Is there anything I am not doing well, please?
Upvotes: 1
Views: 116
Reputation: 33147
I spotted 2 mistakes in your code.
First: The alpha
parameters should be contained in a pure list. Using List Comprehension, the answer is as follows.
Second: In the 'activation': ["logistic", "relu", "Tanh"]}
the Tanh
should be replaced with tanh
.
Replace:
'alpha': [10.0 ** -np.arange(1, 7)]
'activation': ["logistic", "relu", "Tanh"]
With:
'alpha': [10.0 ** -i for i in range(1,7)]
'activation': ["logistic", "relu", "tanh"]
Putting everything together:
parameters={'learning_rate':["constant", "invscaling", "adaptive"],
'hidden_layer_sizes': (156,), 'alpha': [10.0 ** -i for i in range(1,7)],
'activation': ["logistic", "relu", "tanh"]}
grid= GridSearchCV(MLPClassifier(), parameters, n_jobs=-1, cv=10)
grid.fit(train_x, train_y)
Upvotes: 1