I'm trying to figure out the right way to do 5-fold cross-validation in pybrain. I went through their documentation, but that didn't help. I found the following two versions of code online:
Found this one in a question here.
net = pybrain.tools.shortcuts.buildNetwork(5, 8, 1)
trainer = BackpropTrainer(net, ds)
evaluation = ModuleValidator.classificationPerformance(trainer.module, ds)
validator = CrossValidator(trainer=trainer, dataset=trainer.ds, n_folds=5, valfunc=evaluation)
print(validator.validate())
Error:
evaluation = ModuleValidator.classificationPerformance(trainer.module, ds)File ".../pybrain/tools/validation.py", line 168, in classificationPerformancedataset)
File ".../pybrain/tools/validation.py", line 204, in validate return valfunc(output, target)
File ".../pybrain/tools/validation.py", line 33, in classificationPerformance return float(n_correct) / float(len(output))
TypeError: only length-1 arrays can be converted to Python scalars
And the second one here.
modval = ModuleValidator()
for i in range(1000):
trainer.trainEpochs(1)
trainer.trainOnDataset(dataset=trndata)
cv = CrossValidator( trainer, trndata, n_folds=5, valfunc=modval.MSE )
print "MSE %f @ %i" %( cv.validate(), i )
Error - trainer.train()
File ".../rprop.py", line 43, in train for seq in self.ds._provideSequences():
AttributeError: 'NoneType' object has no attribute '_provideSequences'
I went to the source code to try and trace the cause of the error but couldn't figure out what I need to change. Any help appreciated.
When I was running my code by simply dividing the dataset into 3 parts (training, validation and testing) it was working well. I have been getting these errors only when I tried to implement k-fold cross-validation.