Weird results using MLPClassifier in Python with sgd

37 Views Asked by At

I've used the MLPClassifier with default values and the confusion matrix and its chart seems ok.

But when I try to change the "solver" option to "sgd" the results are terrible. In fact, they don't have any sense to me. Am I using something wrong withe MLPClassifier parameters?

My code:

from sklearn import datasets
from sklearn import model_selection
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix
from sklearn import preprocessing
import pandas as pd


cancer = datasets.load_breast_cancer()
x = cancer.data
t = cancer.target
x_norm = preprocessing.scale(x)
tam_test = 0.30
semilla =7
xe, xt, te ,tt = model_selection.train_test_split(x, t, test_size = tam_test, random_state = semilla)

# IF I USE THIS STANDAR CLASSIFIER IS OK
clasificador = MLPClassifier(hidden_layer_sizes=(50,))  
# FROM HEREON NONE OF THEM SEEMS TO SHOW CORRECT RESULTS
# clasificador = MLPClassifier(hidden_layer_sizes=(50), max_iter=300,solver="sgd",learning_rate="adaptive", learning_rate_init=.005)
# clasificador =  MLPClassifier(hidden_layer_sizes=(200,), max_iter=1000, learning_rate_init=.05, solver ="sgd", learning_rate= "adaptive")
# clasificador = MLPClassifier(solver='sgd', hidden_layer_sizes=50,max_iter=150,random_state=0,activation='logistic',alpha=1e-5,learning_rate_init=0.2)

clasificador.fit(xe,te)
obtenido = clasificador.predict(xt)
clasificacion = accuracy_score(tt, obtenido)
print ("Clasificacion: %.4f" %(clasificacion))
matriz_de_confusion = confusion_matrix (tt, obtenido)
print (matriz_de_confusion)
pd.DataFrame(clasificador.loss_curve_).plot()`

You can see here a correct picture use defaults parameters enter image description here

And here a couple of image use any of the non default parameters enter image description here

enter image description here

I've tried to adjust different parameters with MLPClassifier to use SGD but the results seem wrong. I want to know how to use correctly SGD

0

There are 0 best solutions below