[scikit-learn] question in using Scikit-learn MLPClassifier?

Sebastian Raschka se.raschka at gmail.com
Tue Dec 6 11:59:18 EST 2016


Hi,
typically, you want/need to play around with the hyperparameters if you want to get something useful out of an MLP — they rarely work out of the “box” since hyperparameters are very context-dependent.

> However, the accuracy rate is not satisfied comparing to the result in Matlab which use BP algorithm too, I wonder if I should tune the parameter of MLP for better?

Things you may want to try first is 

a) check if the training converged: i.e., check clf.loss_ for e.g., 200, 2000, 5000 iterations. If the loss is noticably smaller after 5000 iterations (compared to 2000 iters), it would tell you that it hasn’t converged yet. Especially stochastic gradient descent is very sensitive to the initial learning rate. I also suggest that you try different values for these. Also, try to use a fixed random seed for reproducibility between runs, e.g., random_state=123

b) If you are using stochastic gradient descent with a logistic activation function, you may want to scale your input features via the StandardScaler so that the features are centered at 0 with std.dev. 1. E.g.,

sc = StandardScaler()
X_train_scaled = sc.fit_transform(X_train)
X_test_scaled = sc.transform(X_test)

Good luck!
Sebastian



> On Dec 6, 2016, at 6:12 AM, linjia at ruijie.com.cn wrote:
> 
> Hi all:
>         I uses a ‘Car Evaluation’ dataset from http://archive.ics.uci.edu/ml/machine-learning-databases/car/car.data to test the effect of MLP.  (I transfer some class in the data to digit value, e.g. ‘low’ to 1 ‘med’ to 2, ‘high ’to 3, the final dataset’s input is 6 dimension, output label is 4 dimension)
>         However, the accuracy rate is not satisfied comparing to the result in Matlab which use BP algorithm too, I wonder if I should tune the parameter of MLP for better?
>  
> Attachment:
>  
> main code in matlab: accuracy 100% after train
> net=newff([-1 1;-1 1;-1 1;-1 1;-1 1;-1 1;],[10 4],{'tansig','logsig'},'trainlm');
>  
> main code in MLP Code: accuracy 70% after fit
> clf = MLPClassifier(solver='sgd', activation='logistic', max_iter=2000, learning_rate='adaptive',warm_start = True)
>  
>  
>  
>  
>  
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn



More information about the scikit-learn mailing list