How to load training data in PyBrain?

橙三吉。 提交于 2019-12-04 04:09:39

Here is how I did it:

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)

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.

You just use pandas arrays this way

import pandas as pd

ds = SupervisedDataSet(6,3)

dataset = pd.read_csv('mycsvfile.csv','r', delimiter=',',skiprows=1)
ds.setfield('input'  dataset.values[:,0:6])
ds.setfield('target',  dataset.values[:,-2:-1])

and you are good to go.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!