I need to train network and then feed it with test data one by one. Is there some example or doc including it?
To achieve that I serialized trained network and I use it with every new incoming entry.
The problem is, I got crash from _convertToOneOfMany
and even tho I understand its purpose (from here) I do not understand how it exactly works.
Its behaviour is not deterministic for me. It must interpret somehow classes and labels and there must be some requirement I am missing. It works for whole data set, however if I take just random line it goes crazy.
Traceback (most recent call last):
File "ffn_iris.py", line 29, in <module>
tstdata._convertToOneOfMany()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PyBrain-0.3-py2.6.egg/pybrain/datasets/classification.py", line 142, in _convertToOneOfMany
newtarg[i, int(oldtarg[i])] = bounds[1]
IndexError: index (2) out of range (0<=index<1) in dimension 1
EDIT: to be more precise let me tell you what I am doing: I want to train network for the most famous NN example in the Internet ;) - Iris Dataset.
It is something like that:
5.1,3.5,1.4,0.2,0
4.9,3.0,1.4,0.2,0
4.7,3.2,1.3,0.2,0
4.6,3.1,1.5,0.2,0
etc...
The last zero it the class. Whole dataset holds 60 rows. 20 for 0, 20 for 1 and 20 for 2.
I read the file with data and construct dataset:
alldata = ClassificationDataSet(4, class_labels=['Iris-setosa',
'Iris-versicolor',
'Iris-virginica'])
--- loop here ---
alldata.addSample(line[0:4], line[4])
--- create testing and training sets ---
tstdata, trndata = alldata.splitWithProportion(0.7)
--- converted matrixes ---
trndata._convertToOneOfMany()
tstdata._convertToOneOfMany()
--- not important, just for completeness ----
fnn = buildNetwork(trndata.indim, 10, trndata.outdim, outclass=SoftmaxLayer)
trainer = BackpropTrainer(fnn, dataset=trndata,
momentum=0.01, verbose=True,
weightdecay=0.01)
My problem relates to _convertToOneOfMany()
. When dataset or datafile holds just couple entries (not 60, divided into three classes) it crashes with exception from the beginning of the question.
Example of crashing datset:
6.5,3.0,5.2,2.0,1
6.5,3.0,5.2,2.0,1
6.2,3.4,5.4,2.3,2
6.5,3.0,5.2,2.0,0
Example of working one:
6.5,3.0,5.2,2.0,1
6.2,3.4,5.4,2.3,2
6.5,3.0,5.2,2.0,0
How can convertToOneOfMany()
be connected to number of entries in the dataset or size of one class subset? One row entries crash as well..