4

I've trained a network on PyBrain for purpose of classification and am ready to fire away with specific input. However, when I do



classes = ['apple', 'orange', 'peach', 'banana']

data = ClassificationDataSet(len(input), 1, nb_classes=len(classes), class_labels=classes)

data._convertToOneOfMany( )                 # recommended by PyBrain

fnn = buildNetwork( data.indim, 5, data.outdim, outclass=SoftmaxLayer ) 

trainer = BackpropTrainer( fnn, dataset=data, momentum=m, verbose=True, weightdecay=wd)

trainer.trainUntilConvergence(maxEpochs=80)

# stop training and start using my trained network here

output = fnn.activate(input)


As expected, I get a numeric value for "output", but is there a way to determine the predicted class label directly? Even if there's not one, how can I map the value of "output" to my class label? Thank you for your help.

user1330974
  • 2,500
  • 5
  • 32
  • 60

1 Answers1

4

When you say you get a numeric value for "output" do you mean a scalar (that is, not an array)? From my understanding of it, you should have gotten an array of four values (ie. as many as possible output classes you have). The biggest value in that array corresponds to the index of the class. I don't know if PyBrain provides an utility function to extract that, but you can do it like this:

class_index = max(xrange(len(output)), key=output.__getitem__)
class_name = classes[class_index]

Incidentally, you omitted the step in which you actually fill the data in the dataset.

Estevo
  • 41
  • 1