使用LSTM预测时间序列2
背景:测试https://blog.csdn.net/a819825294/article/details/54376781 (python利用LSTM进行时间序列分析预测)中的实验
原理:使用历史前50个股票样本的值,预测当前样本的值
数据
0.841470985
0.873736397
0.90255357
0.927808777
0.949402346
0.967249058
0.98127848
0.991435244
0.997679266
0.999985904
....
代码
# -*- coding: utf-8 -*-
import time
import warnings
import numpy as np
import time
import matplotlib.pyplot as plt
from numpy import newaxis
from keras.layers import Dense, Activation, Dropout
from keras.layers import LSTM
from keras.models import Sequential
warnings.filterwarnings("ignore")
def load_data(filename, seq_len, normalise_window):
#open(filename, 'rb').read().decode()
f = open(filename, 'rb').read().decode()
data = f.split('\n')
print('data len:',len(data))
print('sequence len:',seq_len)
sequence_length = seq_len + 1
result = []
for index in range(len(data) - sequence_length):
result.append(data[index: index + sequence_length]) #得到长度为seq_len+1的向量,最后一个作为label
print('result len:',len(result))
print('result shape:',np.array(result).shape)
print(result[:1])
if normalise_window:
result = normalise_windows(result)
print(result[:1])
print('normalise_wind