Вопрос

So I have a ClassificationDataSet in PyBrain which I have trained with the appropriate data. Namely, the input is the following:

trainSet.addSample([0,0,0,0],[1])
trainSet.addSample([0,0,0,1],[0])
trainSet.addSample([0,0,1,0],[0])
trainSet.addSample([0,0,1,1],[1])
trainSet.addSample([0,1,0,0],[0])
trainSet.addSample([0,1,0,1],[1])
trainSet.addSample([0,1,1,0],[1])
trainSet.addSample([0,1,1,1],[0])
trainSet.addSample([1,0,0,0],[0])
trainSet.addSample([1,0,0,1],[1])

The pattern is simple. If there is an even number of 1's then the output should be 1, otherwise it is 0. I want to run the following inputs:

[1,0,0,1],[1]
[1,1,0,1],[0]
[1,0,1,1],[0]
[1,0,1,0],[1]

And see whether the neural network will recognise the pattern. As said previously, I've already trained the network. How do I validate it against the inputs above?

Thanks for your time!

Это было полезно?

Решение

You first have to create a network and train it on your dataset.

Then you have to use activate to get a result from your inputs and test if it matches the desired output.

One easy way to do it is:

testOutput = { [1,0,0,1] : [1], [1,1,0,1] : [0], [1,0,1,1]:[0], [1,0,1,0]:[1] }

for input, expectedOutput in testInput.items():
    output = net.activate(input)
    if output != expectedOutput:
        print "{} didn't match the desired output." 
        print "Expected {}, got {}".format(input, expectedOutput, output)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top