我正在尝试使用PyBrain进行预测,但我的代码输出在测试集上给出了几乎总是相同的预测。谁能解释我为什么?
谢谢!
## ----------------------- 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))
我的代码的第一部分只是数据集。然后是人工神经网络,最后是训练师。我怀疑训练师的编码完全错误。