Search code examples
pythonnolearn

Consistency testing results of NeuralNet nolearn


I am using NeuralNet class in nolearn library to do classification task. Here's the code:

layers0 = [('input', InputLayer),
           ('hidden', DenseLayer),
           ('output', DenseLayer)]

net0 = NeuralNet(layers=layers0,
                 input_shape=(None, 7),
                 hidden_num_units=7,
                 output_num_units=6,
                 output_nonlinearity=softmax,
                 update=nesterov_momentum,
                 update_learning_rate=0.1,
                 update_momentum=0.2,
                 train_split=TrainSplit(eval_size=0),
                 verbose=0,
                 max_epochs=200)
                 net0.fit(X, y)

predict = net0.predict(X_test)
print confusion_matrix(ids, predict)
print "accuracy: ", accuracy_score(ids, predict)

This code trains a NeuralNet and tests it on a test set. But when I run multiple times, each gives a different result. So how can I train the NeuralNet to give only one result given the parameters, training set and testing set?


Solution

  • Simply use seed to random number generator, before calling net0.fit(). For example...

    numpy.random.seed(123)