不打印函数的结果

2024-10-02 02:35:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在用python和pybrain构建神经网络。不幸的是,我的样本非常大,当程序打印出训练中的错误时,我的记忆在程序完成之前就已经满了。在

有没有办法不打印函数中的错误?在

!!!!这不是python错误。这是大脑功能。它打印了预测值与实际样本的差异。例如“错误:0.00424”。在

每次进行预测时,它都会打印这个字符串。在

这是我的密码

ds = SupervisedDataSet(1, 1)
ds.addSample(x,y) <--- in a "for" to add all my sample

net = FeedForwardNetwork() 
inp = LinearLayer(1) 
h1 = SigmoidLayer(1) 
outp = LinearLayer(1)

net.addOutputModule(outp) 
net.addInputModule(inp) 
net.addModule(h1)

net.addConnection(FullConnection(inp, h1))  
net.addConnection(FullConnection(h1, outp))

net.sortModules()

trainer = BackpropTrainer(net, ds)

trainer.trainOnDataset(ds)      ###
trainer.testOnData(verbose=True)### Here is where the function print the errors

net.activate((ind,))

Tags: the程序net错误ds神经网络h1样本
1条回答
网友
1楼 · 发布于 2024-10-02 02:35:33

可以使用try/except,如下所示:

try:
    trainer.testOnData(verbose=True)
except Exception as e:
    <exception handling code>

或者你可以找到错误的来源。你能给你的问题加上错误吗?在

相关问题 更多 >

    热门问题