Caros,
Para fazer um GridSearch de uma rede neural MLP (bem como o da aula: https://cursos.alura.com.br/course/treinando-rede-neural-pytorch/task/68615), deve ser utilizado o MLPRegressor, o KerasRegressor ou outro estimador?
Tentei com esse código:
from sklearn.neural_network import MLPRegressor
from sklearn.model_selection import GridSearchCV
parameters = {"hidden_layer_sizes": [(1,),(10,),(25,)], "activation": ["identity", "logistic", "tanh", "relu"],
"solver": ["rmsprop", "sgd", "adam"], "alpha": [0.001,0.001]}
# "solver": ['adam', 'rmsprop', 'sgd', 'adamax', 'adaw', 'adadelta', 'adagrad', 'asgd', 'nadam'], "alpha": [0.0005,0.001]}
grid_search = GridSearchCV(estimator=MLPRegressor(max_iter=1700), param_grid = parameters, cv = 7, n_jobs=-1)
grid_search.fit(X, y)
best_parameters = grid_search.best_params_
best_score = grid_search.best_score_
print("Best Parameters: " + str(best_parameters))
print("Best scores: " + str(best_score))
...mas falhou:
The above exception was the direct cause of the following exception:
BrokenProcessPool Traceback (most recent call last)
<ipython-input-41-b85f1de870c7> in <cell line: 14>()
12 # "solver": ['adam', 'rmsprop', 'sgd', 'adamax', 'adaw', 'adadelta', 'adagrad', 'asgd', 'nadam'], "alpha": [0.0005,0.001]}
13 grid_search = GridSearchCV(estimator=MLPRegressor(max_iter=1700), param_grid = parameters, cv = 7, n_jobs=-1)
---> 14 grid_search.fit(X, y)
15 best_parameters = grid_search.best_params_
16 best_score = grid_search.best_score_
9 frames
/usr/local/lib/python3.10/dist-packages/joblib/parallel.py in _return_or_raise(self)
752 try:
753 if self.status == TASK_ERROR:
--> 754 raise self._result
755 return self._result
756 finally:
BrokenProcessPool: A task has failed to un-serialize. Please ensure that the arguments of the function are all picklable.
Enfim, vale usar o GridSearch ou gastar tempo fazendo ajustes manuais quando se trabalha com MLP/ANN, CNN, etc? Já usei GridSearch para encontrar hiiperparâmetros para regressão com SVR, Random Forest, Gradient Boosting, AdaBoost, etc e funcionou.