scikit learn hyperparameter optimization for MLPClassifier

tune/adjust hyperparameters MLPClassifier in scikit learn

Two simple strategies to optimize/tune the hyperparameters:

How to tune hyperparameters in scikit learn

mlp_gs = MLPClassifier(max_iter=100)parameter_space = {
'hidden_layer_sizes': [(10,30,10),(20,)],
'activation': ['tanh', 'relu'],
'solver': ['sgd', 'adam'],
'alpha': [0.0001, 0.05],
'learning_rate': ['constant','adaptive'],
}
from sklearn.model_selection import GridSearchCVclf = GridSearchCV(mlp_gs, parameter_space, n_jobs=-1, cv=5)
clf.fit(X, y) # X is train samples and y is the corresponding labels
another example
print('Best parameters found:\n', clf.best_params_)
means = clf.cv_results_['mean_test_score']
stds = clf.cv_results_['std_test_score']
for mean, std, params in zip(means, stds, clf.cv_results_['params']):
print("%0.3f (+/-%0.03f) for %r" % (mean, std * 2, params))
y_true, y_pred = y_test , clf.predict(X_test)from sklearn.metrics import classification_report
print('Results on the test set:')
print(classification_report(y_true, y_pred))
In my example, there are 10 labels (MNIST data set).

Posting daily about Python, Nuclear Physicist PhD