0
from pybrain.structure import FeedForwardNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection
from pybrain.datasets import SupervisedDataSet
import numpy as np

X = np.loadtxt('xdatanorm.txt', dtype=float)
y = np.loadtxt('ydatanorm.txt', dtype=float)

n = FeedForwardNetwork()
inLayer = LinearLayer(35)
hiddenLayer = SigmoidLayer(18)
outLayer = LinearLayer(1)

n.addInputModule(inLayer)
n.addModule(hiddenLayer)
n.addOutputModule(outLayer)

in_to_hidden = FullConnection(inLayer, hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer, outLayer)

n.addConnection(in_to_hidden)
n.addConnection(hidden_to_out)
n.sortModules()

DS = SupervisedDataSet(35,1)
DS.addSample(X,y)

Starting using pybrain to get a Neural Network to work on my diffusion energy data. I don't know how to get a dataset working from my X and y values. X is 35 inputs and y is 1 ouput and there are 148 samples. With this code I get the error: "ValueError: could not broadcast input array from shape (148,35) into shape (35)"

Need to know how to properly prepare a dataset for pybrain.

Liam
  • 1
  • 3

1 Answers1

0

I believe the .addSample() method expects one sample at a time. Rather than using .addSample(), try

assert(X.shape[0] == y.shape[0])
DS.setField('input', X)
DS.setField('target', y)

The 'assert()' is recommended because the .setField() method does not verify array dimensions like .addSample() does.

See Pybrain dataset tutorial for more info.

George
  • 1