Different predictions on multiple run of the same algorithm scikit neural network Since a MLP can implement any function. I have the following code, using which I am trying to implement the AND function. But what I find that on running the program multiple times, I end up getting different predicted values. Why is this happening ? Also how does one determine which type of activation function has to be provided at different layers ?
from sknn.mlp import Regressor,Layer,Classifier
import numpy as np   
X_train = np.array([[0,0],[0,1],[1,0],[1,1]])
y_train = np.array([0,0,0,1])
nn = Classifier(layers=[Layer("Softmax", units=2)],learning_rate=0.001,n_iter=25)
nn.fit(X_train, y_train)
X_example = np.array([[0,0],[0,1],[1,0],[1,1]])
y_example = nn.predict(X_example)
print (y_example)

 A: For reproducibility you should set the random seed for your code.
import random
random.seed(2016)

Random seed accepts any hashable object. You will most commonly see a number in there. It is an optional argument, if you don't pass it it will use the system time as seed.
Another way to achieve reproducible results is to set the random_state=int as argument of Classifier in your code.
You can use any number of hidden layers. In order to set the function for each layer, define the first argument of Layer(). That's 'Softmax' in your code.
It is recommended to use a pipeline for the construction of your network. You should also normalize your data. In the below code you can see an example:
from sknn.mlp import Classifier, Layer
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler

pipeline = Pipeline([
        ('min/max scaler', MinMaxScaler(feature_range=(0.0, 1.0))), #normalization
        ('neural network', Classifier(layers=[Layer("Softmax")], n_iter=25))])

Then you call
pipeline.fit(X_train, y_train)

