如何在PyBrain中加载训练数据? [英] How to load training data in PyBrain?

查看:75
本文介绍了如何在PyBrain中加载训练数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PyBrain进行一些简单的NN训练.我不知道该怎么做是从文件中加载训练数据.在他们的网站上没有任何说明.我不在乎格式,因为我现在可以构建它,但是我需要在文件中完成它,而不是手动逐行添加,因为我将有数百行.

I am trying to use PyBrain for some simple NN training. What I don't know how to do is to load the training data from a file. It is not explained in their website anywhere. I don't care about the format because I can build it now, but I need to do it in a file instead of adding row by row manually, because I will have several hundreds of rows.

推荐答案

这是我的操作方式:


ds = SupervisedDataSet(6,3)

tf = open('mycsvfile.csv','r')

for line in tf.readlines():
    data = [float(x) for x in line.strip().split(',') if x != '']
    indata =  tuple(data[:6])
    outdata = tuple(data[6:])
    ds.addSample(indata,outdata)

n = buildNetwork(ds.indim,8,8,ds.outdim,recurrent=True)
t = BackpropTrainer(n,learningrate=0.01,momentum=0.5,verbose=True)
t.trainOnDataset(ds,1000)
t.testOnData(verbose=True)

在这种情况下,神经网络有6个输入和3个输出. csv文件的每行有9个值,用逗号分隔.前6个值是输入值,后三个是输出.

In this case the neural network has 6 inputs and 3 outputs. The csv file has 9 values on each line separated by a comma. The first 6 values are input values and the last three are outputs.

这篇关于如何在PyBrain中加载训练数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆