Reputation: 566
I am trying to learn Neural Networks using scikit-neuralnetwork framework and I know basics about Neural Networks and now trying to implement it with scikit-learn. but I am confused on 2 points.
1- what is the structure of this NN given below? Somehow, in some examples felt to me, some people don't put input layer as a layer. Otherwise, I am thinking this as a 2 layer NN has input layer with 100 nodes and 1 node at the ouput layer.
from sknn.mlp import Classifier, Layer
nn = Classifier(
layers=[
Layer("Maxout", units=100, pieces=2),
Layer("Softmax")],
learning_rate=0.001,
n_iter=25)
nn.fit(X_train, y_train)
2- Does scikit-neuralnetwork do back propagation within the code that I put above?
Thank you!
Upvotes: 0
Views: 913
Reputation: 566
1- In scikit-neuralnetwork framework, the input layer is not shown but it is creared in the background as a layer when we feed the system with training data.
nn.fit(X_train, y_train)
for example, let's suppose we are using iris flower dataset. It has 3 classes so if that's the case framework understands that from the y_train and it creates 3 input layer with 3 classes.
y_train = [0,0,0,1,2,]
X_train = [[ 7.1 3. 5.9 2.1]
[ 5.9 3. 4.2 1.5]
[ 5.5 2.4 3.7 1. ]
[ 6.1 2.8 4.7 1.2]
[ 5. 2.3 3.3 1. ]]
Except for the last layer, all of the other layers are hidden layer. I saw that when I manipulate the last layer, got this error
nn = Classifier(
layers=[
Layer("Maxout", units=100, pieces=2),
Layer("Softmax",units=1)], -----> if units is 3 that's ok!
learning_rate=0.001,
n_iter=25)
"Mismatch between dataset size and units in output layer."
AssertionError: Mismatch between dataset size and units in output layer.
2- More detailed explanation; thanks to @robintibor at datascience.stackexchange. He explained both questions here Explanation
and thank you @user7534232 for your answer too :)
Upvotes: 0
Reputation: 11
1.
Assuming that each training example in X_train
has M features, and there are C classes in y_train
:
The input layer (not explicitly shown in the code) has M nodes. The hidden layer has 100 nodes. The output layer has C nodes (each one encoding the score for each class).
2.
.fit()
is a method that does that - feeds forward the training examples and uses back propagation to train the NN.
Also: perhaps you have to add units=C
for the final layer - I assume this is a classification problem. If you need one value only (a score, not a class label), then use Regressor
.
Upvotes: 1