user123
user123

Reputation: 5407

Scikit learn multilayer neural network

As per the documentation provided by Scikit learn

hidden_layer_sizes : tuple, length = n_layers - 2, default (100,)

I have little doubt.

In my code what I have configured is

MLPClassifier(algorithm='l-bfgs', alpha=1e-5, hidden_layer_sizes=(5, 2), random_state=1)

so what does 5 and 2 indicates?

What I understand is, 5 is the numbers of hidden layers, but then what is 2?

Ref - http://scikit-learn.org/dev/modules/generated/sklearn.neural_network.MLPClassifier.html#

Upvotes: 3

Views: 2653

Answers (2)

seralouk
seralouk

Reputation: 33147

Some details that I found online concerning the architecture and the units of the input, hidden and output layers in sklearn.

  • The number of input units will be the number of features
  • For multiclass classification the number of output units will be the number of labels
  • Try a single hidden layer, or if more than one then each hidden layer should have the same number of units
  • The more units in a hidden layer the better, try the same as the number of input features up to twice or even three or four times that

Upvotes: 0

pltrdy
pltrdy

Reputation: 2109

From the link you provided, in parameter table, hidden_layer_sizes row:

The ith element represents the number of neurons in the ith hidden layer

Which means that you will have len(hidden_layer_sizes) hidden layers, and, each hidden layer i will have hidden_layer_sizes[i] neurons.

In your case, (5, 2) means:

  • 1rst hidden layer has 5 neurons
  • 2nd hidden layer has 2 neurons

So the number of hidden layers is implicitely set

Upvotes: 8

Related Questions