Python scikit learn MLPClassifier "hidden_layer_sizes"
Solution 1
hidden_layer_sizes=(7,)
if you want only 1 hidden layer with 7 hidden units.
length = n_layers - 2
is because you have 1 input layer and 1 output layer.
Solution 2
In the docs:
hidden_layer_sizes : tuple, length = n_layers - 2, default (100,)
means : hidden_layer_sizes is a tuple of size (n_layers -2)
n_layers means no of layers we want as per architecture.
Value 2 is subtracted from n_layers because two layers (input & output ) are not part of hidden layers, so not belong to the count.
default(100,) means if no value is provided for hidden_layer_sizes then default architecture will have one input layer, one hidden layer with 100 units and one output layer.
From the docs again:
The ith element represents the number of neurons in the ith hidden layer.
means each entry in tuple belongs to corresponding hidden layer.
Example :
-
For architecture 56:25:11:7:5:3:1 with input 56 and 1 output hidden layers will be (25:11:7:5:3). So tuple
hidden_layer_sizes = (25,11,7,5,3,)
-
For architecture 3:45:2:11:2 with input 3 and 2 output hidden layers will be (45:2:11). So tuple
hidden_layer_sizes = (45,2,11,)
Chubaka
Updated on July 09, 2022Comments
-
Chubaka almost 2 years
I am lost in the scikit learn 0.18 user manual (http://scikit-learn.org/dev/modules/generated/sklearn.neural_network.MLPClassifier.html#sklearn.neural_network.MLPClassifier):
hidden_layer_sizes : tuple, length = n_layers - 2, default (100,) The ith element represents the number of neurons in the ith hidden layer.
If I am looking for only 1 hidden layer and 7 hidden units in my model, should I put like this? Thanks!
hidden_layer_sizes=(7, 1)
-
Chubaka about 8 yearsThanks! This is the confusing part. What if I am looking for 3 hidden layer with 10 hidden units? hidden_layer_sizes=(10,1)?
-
Farseer about 8 years(10,10,10) if you want 3 hidden layers with 10 hidden units each.
-
Chubaka about 8 yearsSo my undnerstanding is the default is 1 hidden layers with 100 hidden units each? Thanks!
-
E B over 6 years@Farseer, if you want to test this NN architecture : 56:25:11:7:5:3:1., The 56 is the input layer and the output layer is 1 , hidden_layer_sizes=(25,11,7,5,3)?
-
AAI over 4 yearsthen how does the machine learning know the size of input and output layer in sklearn settings?
-
shantanu pathak over 4 yearswhen you fit() (train) the classifier it fixes number of input neurons equal to number features in each sample of data. And no of outputs is number of classes in 'y' or target variable.