简体   繁体   English

如何测试用PyBrain开发的神经网络

[英]How to test neural network developed with PyBrain

I'm new to machine learning and am trying to learn how to develop neural networks for prediction purposes in Python. 我是机器学习的新手,正在尝试学习如何在Python中开发用于预测目的的神经网络。 I followed a basic tutorial from PyBrain and have successfully set up a neural network and have trained it (supervised learning). 我遵循了PyBrain的基础教程,并成功地建立了神经网络并对其进行了训练(监督学习)。 Here is the code: 这是代码:

ds = SupervisedDataSet(2, 1)
ds.addSample((0, 0), (0,))
ds.addSample((0, 1), (1,))
ds.addSample((1, 0), (1,))
ds.addSample((1, 1), (0,))

network = buildNetwork(2, 3, 1, bias=True, hiddenclass=TanhLayer)
trainer = BackpropTrainer(network, ds)
trainer.trainUntilConvergence()

I'm now not sure how to test this network with new data. 我现在不确定如何用新数据测试该网络。 I have tried the activate() method of the Network class ( http://pybrain.org/docs/api/structure/networks.html ) and the testOnClassData() method of the Trainer class ( http://pybrain.org/docs/api/supervised/trainers.html ), but a) I'm not sure how they work, and b) based on the documentation, I'm not sure they serve my purpose, which is to train the network to successfully predict an outcome given input parameters. 我已经尝试了Network类( http://pybrain.org/docs/api/structure/networks.html )的activate()方法和Trainer类( http://pybrain.org/ )的testOnClassData()方法。 docs / api / supervised / trainers.html ),但是a)我不确定它们如何工作,b)基于文档,我不确定它们是否达到我的目的,这是训练网络成功预测给定输入参数的结果。

Does anyone know how to test a neural network developed in PyBrain such as mine? 有谁知道如何测试在PyBrain中开发的神经网络,例如我的? Thank you very much in advance! 提前非常感谢您! :) :)

ts = UnsupervisedDataSet(inputLength,)
ts.addSample((0,0))
net.activateOnDataset(ts)[0]

To test the network now feed some inputs without output. 为了测试网络,现在输入一些输入而没有输出。

 from pybrain.datasets import UnsupervisedDataSet  
    dst = UnsupervisedDataSet(2, )
    dst.addSample((0, 1))
    result=network.activateOnDataset(dst)[0]
    print(result)

if you use multiple inputs use for loop for 如果您使用多个输入,请使用for循环

network.activateOnDataset()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM