交叉验证 - TypeError:只能将length-1数组转换为Python标量

时间:2015-11-17 15:11:25

标签: python pybrain

我正在尝试使用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())

问题出在这里有什么建议吗?

0 个答案:

没有答案