使用LSTM预测股票数据

使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值