LSTM自动编码器,用于时间序列预测 [英] LSTM Autoencoder for time series prediction

查看:514
本文介绍了LSTM自动编码器,用于时间序列预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建LSTM自动编码器以预测时间序列数据.由于我是Python新手,因此在解码部分会出错.我尝试在此处

I am trying to build an LSTM Autoencoder to predict Time Series data. Since I am new to Python I have mistakes in the decoding part. I tried to build it up like here and Keras. I could not understand the difference between the given examples at all. The code that I have right now looks like:

问题1:当每个样本有2000个值时,如何选择batch_size和input_dimension?

Question 1: is how to choose the batch_size and input_dimension when each sample has 2000 values?

问题2:如何使LSTM自动编码器正常工作(模型和预测)?这仅是模型,但如何预测?可以说是从样本10开始直到数据结束吗?

Question 2: How to get this LSTM Autoencoder working (the model and the prediction) ? This ist just the model, but how to predict? That it is predicting from the lets say starting from sample 10 on till the end of the data?

Mydata总共有1500个样本,我将使用10个时间步长(如果更好,则更多),每个样本具有2000个值.如果您需要更多信息,我也会在以后将它们包括在内.

Mydata has in total 1500 samples, I would go with 10 time steps (or more if better), and each sample has 2000 Values. If you need more information I would include them as well later.

trainX = np.reshape(data, (1500, 10,2000))

from keras.layers import *
from keras.models import Model
from keras.layers import Input, LSTM, RepeatVector

参数

timesteps=10
input_dim=2000
units=100 #choosen unit number randomly
batch_size=2000 
epochs=20

型号

inpE = Input((timesteps,input_dim)) 
outE = LSTM(units = units, return_sequences=False)(inpE)
encoder = Model(inpE,outE) 
inpD = RepeatVector(timesteps)(outE)
outD1 = LSTM(input_dim, return_sequences=True)(outD
decoder = Model(inpD,outD) 
autoencoder = Model(inpE, outD)
autoencoder.compile(loss='mean_squared_error',
          optimizer='rmsprop',
          metrics=['accuracy'])
autoencoder.fit(trainX, trainX,
      batch_size=batch_size,
      epochs=epochs)
encoderPredictions = encoder.predict(trainX)

推荐答案

我使用的LSTM模型是这样的:

The LSTM model that I use is this one:

def get_model(n_dimensions):
    inputs = Input(shape=(timesteps, input_dim))
    encoded = LSTM(n_dimensions, return_sequences=False, name="encoder")(inputs)
    decoded = RepeatVector(timesteps)(encoded)
    decoded = LSTM(input_dim, return_sequences=True, name='decoder')(decoded)

    autoencoder = Model(inputs, decoded)
    encoder = Model(inputs, encoded)
    return autoencoder, encoder

autoencoder, encoder = get_model(n_dimensions)
autoencoder.compile(optimizer='rmsprop', loss='mse', 
                    metrics=['acc', 'cosine_proximity'])

history = autoencoder.fit(x, x, batch_size=100, epochs=100)
encoded = encoder.predict(x)

它适用于x大小为(3000, 180, 40)的数据,即3000个样本timesteps=180input_dim=40.

It works with the data that have, x is of size (3000, 180, 40), that is 3000 samples, timesteps=180 and input_dim=40.

这篇关于LSTM自动编码器,用于时间序列预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆