我正在尝试使用CrossValidator
对我的数据执行交叉验证任务。但是,它不起作用,而是给我以下错误:
Traceback (most recent call last):
File "/home/sfalk/workspace/SemEval2016/java/semeval2016-python/semeval_slot1_pybrain_cv.py", line 173, in <module>
evaluation = ModuleValidator.classificationPerformance(trainer.module, ds)
File "/usr/local/lib/python2.7/dist-packages/pybrain/tools/validation.py", line 168, in classificationPerformance
dataset)
File "/usr/local/lib/python2.7/dist-packages/pybrain/tools/validation.py", line 204, in validate
return valfunc(output, target)
File "/usr/local/lib/python2.7/dist-packages/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
代码:
trainer = BackpropTrainer( fnn, momentum=0.1, verbose=False, weightdecay=0.0)
for j in range(len(X_train)):
x = X_train[j]
y = Y_train[j]
ds = SupervisedDataSet(len(x), len(y))
ds.addSample(x, y)
trainer.trainOnDataset(dataset=ds)
trainer = BackpropTrainer(fnn, ds)
evaluation = ModuleValidator.classificationPerformance(trainer.module, ds)
validator = CrossValidator(trainer=trainer, dataset=trainer.ds, n_folds=5, valfunc=evaluation)
print(validator.validate())
问题出在这里有什么建议吗?