[英]I am writing neural-network for predicate value in the time series
dear friends!亲爱的朋友们!
At this moment I am trying to write code of Neural-network in keras, which will predict some value in time series.目前我正在尝试在 keras 中编写 Neural-network 的代码,这将预测时间序列中的一些值。 The time series have form like "0...0 N 0...0 N 0...0", where number of zeros between N's is the same.
时间序列的形式类似于“0...0 N 0...0 N 0...0”,其中 N 之间的零数相同。
For this target i am using LSTM-layers.对于这个目标,我正在使用 LSTM 层。 I've been struggling with this task for over a week, but my network is really bad now
我已经为这个任务苦苦挣扎了一个多星期,但我的网络现在真的很糟糕
For this target i am using LSTM-layers.对于这个目标,我正在使用 LSTM 层。 I've been struggling with this task for over a week, but my network is really bad yet (loss are very big and they aren't reduced during fit)
我已经为这项任务苦苦挣扎了一个多星期,但是我的网络还很糟糕(损失非常大,并且在适应期间并没有减少)
Mo model looks like莫 model 看起来像
model = Sequential()
model.add(LSTM(60, activation = softplus, use_bias = True, return_sequences = True, input_shape = (1, sample)))
model.add(LSTM(60, activation = softplus, use_bias = True, return_sequences = True))
model.add(LSTM(60, activation = softplus, use_bias = True))
model.add(Dropout(0.05))
model.add(Dense(1))
model.compile(loss = 'MSE',
optimizer = 'RMSProp',
metrics = ['accuracy', 'mae'])
model.fit(
x = trainX, y = trainY,
batch_size = batch_size,
epochs = 1000,
shuffle=True,
validation_data=(testX, testY),
callbacks = [cp_callback])
What wrong with this code?这段代码有什么问题? And what should I do to make my network better?
我应该怎么做才能使我的网络更好?
Thank you for answer!谢谢你的答案!
Ps: I am really new in Neural Networks, so I am really sorry if my question is stupid. Ps:我是神经网络的新手,如果我的问题很愚蠢,我真的很抱歉。 And sorry for my English too:)
也对不起我的英语:)
You might want to try simplifying the network, also scaling the input down from 1000 to 1 might help.您可能想尝试简化网络,将输入从 1000 缩小到 1 可能会有所帮助。 I created a simplified network which has good accuracy which might help point you in the right direction.
我创建了一个简化的网络,该网络具有良好的准确性,可能有助于为您指明正确的方向。 I hope this helps.
我希望这有帮助。
from keras.models import Sequential
from keras.layers import LSTM, Dense
import numpy as np
data_dim = 1
timesteps = 11
# expected input data shape: (batch_size, timesteps, data_dim)
model = Sequential()
model.add(LSTM(4, input_shape=(timesteps, data_dim))) # returns a sequence of vectors of dimension 4
model.add(Dense(2))
model.add(Dense(1))
model.compile(loss='mse',
optimizer='rmsprop',
metrics=['accuracy'])
# Generate dummy training data
x_train = np.array([[0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0]])
x_train = np.expand_dims(x_train,axis=2)
y_train = np.array([[1], [0]])
model.summary()
print(x_train.shape)
print(y_train.shape)
model.fit(x_train, y_train, batch_size=2, epochs=200)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.