PyBrain Prediction Error

I am trying to predict the selling price of a given set of products. I am using RecurrentNetwork and BackpropTrainer in pybrain. Here is my code

def nnet(train, target, valid): ds = SupervisedDataSet(52-len(NU)+5, 1) for i in range(len(train)): ds.appendLinked(train[i], target[i]) n = RecurrentNetwork() n.addInputModule(LinearLayer(52-len(NU)+5, name='in')) n.addModule(SigmoidLayer(3, name='hidden')) n.addOutputModule(LinearLayer(1, name='out')) n.addConnection(FullConnection(n['in'], n['hidden'], name='c1')) n.addConnection(FullConnection(n['hidden'], n['out'], name='c2')) n.addRecurrentConnection(FullConnection(n['hidden'], n['hidden'], name='c3')) n.sortModules() t = BackpropTrainer(n,learningrate=0.001,verbose=True) t.trainOnDataset(ds, 20) prediction = np.zeros((11573, 1), dtype = int) for i in range(11573): prediction[i] = n.activate(valid[i]) return prediction 

Here, the train and the target, which are numpy arrays, are used to train the model, and 52-len (NU) +5 is the number of attributes (attributes). For each item in action, we must predict the selling price. The problem is that for every item in action I get the same selling price, except for the first one. What have I done wrong? Thanks in advance.

The dimensions of the array are as follows:

train - 401125, 52-len (NU) +5

target - 401125, 1

valid - 11573, 52-len (NU) +5

+4
source share
1 answer

I'm not sure about the specific implementation details of PyBrain, but I see two possibilities.

1) Backpropagation does not work with linear activation features. Depending on the implementation details of PyBrain, changing both instances of LinearLayer to SigmoidLayer can fix this problem.

2) With recurrent neural networks, you should use backpropagation over time (an algorithm specially adapted for RNN) instead of the usual backpropagation. Depending on the implementation details of PyBrain, there may be a separate class for this option. It is worth checking out.

+3
source

All Articles