你好,
我有一个看起来像这样的序列(加上更多的零):
[ 0, 0.66 , 0 ,0.66 ,0 ,0 ,0 ,0.55 ,0 ,0 ,0 ,3.18 ,0 ,0 ,2 ,0.6 ,0]
我在 python 中有以下代码,其方式与:
from pybrain.datasets import SequentialDataSet
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure.modules import LSTMLayer
from pybrain.supervised import RPropMinusTrainer
from itertools import cycle
ds = SequentialDataSet(1, 1)
for sample, next_sample in zip(train, cycle(train[1:])):
ds.addSample(sample, next_sample)
net = buildNetwork(1, 5, 1, hiddenclass=LSTMLayer, outputbias=False, recurrent=True)
trainer = RPropMinusTrainer(net, dataset=ds)
train_errors = []
EPOCHS_PER_CYCLE = 5
CYCLES = 50
EPOCHS = EPOCHS_PER_CYCLE * CYCLES
for i in range(CYCLES):
trainer.trainEpochs(EPOCHS_PER_CYCLE)
train_errors.append(trainer.testOnData())
epoch = (i+1) * EPOCHS_PER_CYCLE
print("\r epoch {}/{}".format(epoch, EPOCHS), end="")
stdout.flush()
在训练集上获得预测:
res=[]
for sample, target in ds.getSequenceIterator(0):
r=net.activate(sample)
res.append(r)
然后我注意到网络从不预测零,总是在 0.10 左右。我应该如何调整我的网络以获得良好的结果?
谢谢