Meaning of attribute n_layers_ in sklearn.neural_network.MLPClassifier
Meaning of attribute n_layers_ in sklearn.neural_network.MLPClassifier
I have trained a model using sklearn.neural_network.MLPClassifier
and I want to know how many layers are in my clssifier. The result shows :
sklearn.neural_network.MLPClassifier
>>from sklearn.neural_network import MLPClassifier
>>clf = MLPClassifier()
>>clf = clf.fit(train_matrix,train_label)
>>clf.n_layers_
>>3
The document shows attribute n_layers_ means :
Number of layers
Dose it mean there is a hidden layer or there are three hidden layers?
1 Answer
1
n_layers_
denotes all the layers in the neural network which include
n_layers_
len(hidden_layer_sizes)
So if you initialized the classifier as
clf = MLPClassifier()
The default hidden_layer_sizes
param = (100,)
, so number of hidden layers = 1.
hidden_layer_sizes
(100,)
So total layers = 1+1+1 = 3 as you are getting.
If instead you initialized it as:
clf = MLPClassifier(hidden_layer_sizes=(100,100,))
Now the number of hidden layers = 2, so total layers = 4
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy