Getting output of pybrain prediction as array
Asked Answered
G

1

7

I am making use of pybrain to build a network that has 6 input dimensions and one real valued output dimension. The code I use is shown below:

network = buildNetwork(train.indim, 4, train.outdim)

trainer = BackpropTrainer( network, train)
trainer.trainOnDataset(train, 8000)

print 'MSE train', trainer.testOnData(train, verbose = True)

here train is of type Dataset I want to get the predictions made in trainer.testOnData() as a numpy array. I am able to view the predicted result along with the error but I want it as an array. Is there anyway that this can be done?

Grog answered 22/4, 2013 at 7:5 Comment(0)
R
4

Use the activate function of your network:

numpy.array([network.activate(x) for x, _ in train])

Complete example:

from datasets import XORDataSet 
from pybrain.tools.shortcuts import buildNetwork
from pybrain.supervised import BackpropTrainer
import numpy
d = XORDataSet()
n = buildNetwork(d.indim, 4, d.outdim, bias=True)
t = BackpropTrainer(n, learningrate=0.01, momentum=0.99, verbose=True)
t.trainOnDataset(d, 1000)
t.testOnData(verbose=True)
print numpy.array([n.activate(x) for x, _ in d])

(Only works in the directory pybrain/examples/supervised/backprop of pybrain because the XORDataSet is required.)

Reamy answered 22/4, 2013 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.