Search code examples
pythonscikit-learnneural-networkartificial-intelligencemlp

how change learnrate and hidden layers of a MLP network with sklearn


I'm doing a cross validation with sklearn.cross_validation.cross_val_score function to a multilayer perceptron

from sklearn import svm
import numpy as np
from sklearn.model_selection import cross_val_score

clf = svm.SVC(gamma='auto')

scores = cross_val_score(clf, X, np.ravel(y), cv=5, scoring='accuracy')

The cross validation is working and returning 0.8579100145137881. How can I change de number of learnrate or hidden layers with the sklearn? I want improve the accuracy.


Solution

  • from sklearn import svm
    import numpy as np
    
    from sklearn.neural_network import MLPClassifier
    clf = MLPClassifier(solver='sgd', hidden_layer_sizes=(4,4), learning_rate_init=0.05, activation='logistic', max_iter=30000)
    
    from sklearn.model_selection import cross_val_score
    scores = cross_val_score(clf, X, np.ravel(y), cv=5, scoring='accuracy')