2

I'm trying to use PyBrain for predicition, but my code's output gives my almost always the same prediction on a test set. Could anyone explain me why ?

Thanks !

## ----------------------- Data ---------------------------- ##
import pandas as pd

bdata = pd.read_csv(r'C:\Users\philippe.colo\Projects\regret\data\MT_161.csv', delimiter=';', na_values=0, nrows=96*3,
                     index_col=0, parse_dates=True, infer_datetime_format=True)

# 0: weekday, 1: month, 2: time, 3: monthday

X = []

for k, v in bdata.iterrows():
    dow = k.dayofweek
    day = k.day
    mth = k.month
    sec = k.hour * 3600 + k.minute * 60
    X.append([dow, day, mth, sec])

Y = bdata.values

from pybrain.datasets import SupervisedDataSet
DS = SupervisedDataSet(4, 1)
for i in range(0, 96*2):
        DS.addSample((X[i][0], X[i][1], X[i][2], X[i][3],), (float(Y[i]),))


## ----------------------- ANN ---------------------------- ##

from pybrain.structure import FeedForwardNetwork
n = FeedForwardNetwork()

from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection

n.addInputModule(LinearLayer(4, 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.sortModules() #initialisation


## ----------------------- Trainer ---------------------------- ##

from pybrain.supervised.trainers import BackpropTrainer

tstdata, trndata = DS.splitWithProportion(0.25)

#print len(tstdata)
#print len(trndata)

trainer = BackpropTrainer(module=n, dataset=DS)

#print trainer.trainUntilConvergence()
trainer.trainOnDataset(trndata, 100)


print n.activate((2, 1, 3, 0))
print n.activate((2, 1, 3, 90))

The first part of my code is just the data set. Then comes the artificial neural network and finally the trainer. I suspect the trainer to be totally badly coded.

P. Colo
  • 21
  • 1
  • Why did you comment out `trainUntilConvergence`? – doctorlove Aug 13 '15 at 15:53
  • There might be some clues in here - http://stackoverflow.com/questions/12050460/neural-network-training-with-pybrain-wont-converge Make sure it gets a fair mix of test data and maybe try more than one epoch. – doctorlove Aug 14 '15 at 09:30
  • @doctorlove just for you to know I tried both training protocoles, which didn't change the result. – P. Colo Aug 14 '15 at 09:35
  • Thanks for the link. I've tried to take the epoch and learningrate issues into account but it didn't change my problem. My ANN is still prediciting exactly the same feature for an entire dataset, whatever its size is ... – P. Colo Aug 14 '15 at 10:09
  • Without seeing the data I don't think I can help. Sorry. – doctorlove Aug 14 '15 at 10:12
  • It's electricity consumption data from one household during a year measured every 15 minutes. The inputs are the day of the week, the day of the month, the month and the second of the day. The feature is the corresponding consumption. I can mail you the database if you like – P. Colo Aug 14 '15 at 10:27

0 Answers0