Lee Jack
Lee Jack

Reputation: 191

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 :

>>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?

Upvotes: 2

Views: 2149

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 36599

n_layers_ denotes all the layers in the neural network which include

  1. Input layer = 1
  2. All hidden layers = len(hidden_layer_sizes)
  3. Output layer = 1

So if you initialized the classifier as

clf = MLPClassifier()

The default hidden_layer_sizes param = (100,), so number of hidden layers = 1.

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

Upvotes: 7

Related Questions