I am new to Pybrain and trying to put together a neural network. First, I came across the error described here:
AttributeError: 'SupervisedDataSet' object has no attribute '_convertToOneOfMany'
I tried the workaround described in the accepted answer of that thread. While it seems it works, it now gives me a new error. These are the relevant chunks of my code:
The part that reads the file into a classification dataset. 3 input attributes, 2 classes, splits the read array, first 3 columns to 'input' and the last one to 'target':
ds = ClassificationDataSet(inp=3, target=1, nb_classes=2)
tf = open('datafile.txt')
a = np.loadtxt(tf)
a = np.hsplit(a, (3,4))
ds.setField('input', a[0])
ds.setField('target', a[1])
The part that builds a simple network, pretty standard for pybrain:
inLayer = SigmoidLayer(3)
hiddenLayer = SigmoidLayer(5)
outLayer = SigmoidLayer(2)
fnn.addInputModule(inLayer)
fnn.addModule(hiddenLayer)
fnn.addOutputModule(outLayer)
in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)
fnn.addConnection(in_to_hidden)
fnn.addConnection(hidden_to_out)
fnn.sortModules()
This is the workaround, as described above:
tstdata_temp, trndata_temp = ds.splitWithProportion(0.25)
tstdata = ClassificationDataSet(3, target=1, nb_classes=2)
for n in xrange(0, tstdata_temp.getLength()):
tstdata.addSample( tstdata_temp.getSample(n)[0], tstdata_temp.getSample(n)[1] )
trndata = ClassificationDataSet(3, target=1, nb_classes=2)
for n in xrange(0, trndata_temp.getLength()):
trndata.addSample( trndata_temp.getSample(n)[0], trndata_temp.getSample(n)[1] )
trndata._convertToOneOfMany()
tstdata._convertToOneOfMany()
And this is the error I am getting on the first convert line:
IndexError: index 2 is out of bounds for axis 1 with size 2