深度学习100例-循环神经网络(LSTM)实现股票预测 | 第10天

一、前言

今天是第10天,我们将使用LSTM完成股票开盘价格的预测,最后的R2可达到0.74,相对传统的RNN的0.72提高了两个百分点。

我的环境:

  • 语言环境:Python3.6.5
  • 编译器:jupyter notebook
  • 深度学习环境:TensorFlow2.4.1

来自专栏:【深度学习100例】

往期精彩内容:

如果你还是一名小白,可以看看我这个专门为你写的专栏:《小白入门深度学习》,帮助零基础的你入门深度学习。

二、LSTM的是什么

神经网络程序的基本流程
在这里插入图片描述

一句话介绍LSTM,它是RNN的进阶版,如果说RNN的最大限度是理解一句话,那么LSTM的最大限度则是理解一段话,详细介绍如下:

LSTM,全称为长短期记忆网络(Long Short Term Memory networks),是一种特殊的RNN,能够学习到长期依赖关系。LSTM由Hochreiter & Schmidhuber (1997)提出,许多研究者进行了一系列的工作对其改进并使之发扬光大。LSTM在许多问题上效果非常好,现在被广泛使用。

所有的循环神经网络都有着重复的神经网络模块形成链的形式。在普通的RNN中,重复模块结构非常简单,其结构如下:

在这里插入图片描述

LSTM避免了长期依赖的问题。可以记住长期信息!LSTM内部有较为复杂的结构。能通过门控状态来选择调整传输的信息,记住需要长时间记忆的信息,忘记不重要的信息,其结构如下:

在这里插入图片描述

三、准备工作

1.设置GPU

如果使用的是CPU可以注释掉这部分的代码。

import tensorflow as tf

gpus = tf.config.list_physical_devices("GPU")

if gpus:
    tf.config.experimental.set_memory_growth(gpus[0], True)  #设置GPU显存用量按需使用
    tf.config.set_visible_devices([gpus[0]],"GPU")

2.设置相关参数

import pandas            as pd
import tensorflow        as tf  
import numpy             as np
import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

from numpy                 import array
from sklearn               import metrics
from sklearn.preprocessing import MinMaxScaler
from keras.models          import Sequential
from keras.layers          import Dense,LSTM,Bidirectional


# 确保结果尽可能重现
from numpy.random          import seed
seed(1)
tf.random.set_seed(1)

# 设置相关参数
n_timestamp  = 40    # 时间戳
n_epochs     = 20    # 训练轮数
# ====================================
#      选择模型:
#            1: 单层 LSTM
#            2: 多层 LSTM
#            3: 双向 LSTM
# ====================================
model_type 
  • 1
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
新论文:最近6个月以内的 Batch Renormalization: Towards Reducing Minibatch Dependence in Batch-Normalized Models, S. Ioffe. Wasserstein GAN, M. Arjovsky et al. Understanding deep learning requires rethinking generalization, C. Zhang et al. [pdf] 老论文:2012年以前的 An analysis of single-layer networks in unsupervised feature learning (2011), A. Coates et al. Deep sparse rectifier neural networks (2011), X. Glorot et al. Natural language processing (almost) from scratch (2011), R. Collobert et al. Recurrent neural network based language model (2010), T. Mikolov et al. Stacked denoising autoencoders: Learning useful representations in a deep network with a local denoising criterion (2010), P. Vincent et al. Learning mid-level features for recognition (2010), Y. Boureau A practical guide to training restricted boltzmann machines (2010), G. Hinton Understanding the difficulty of training deep feedforward neural networks (2010), X. Glorot and Y. Bengio Why does unsupervised pre-training help deep learning (2010), D. Erhan et al. Recurrent neural network based language model (2010), T. Mikolov et al. Learning deep architectures for AI (2009), Y. Bengio. Convolutional deep belief networks for scalable unsupervised learning of hierarchical representations (2009), H. Lee et al. Greedy layer-wise training of deep networks (2007), Y. Bengio et al. Reducing the dimensionality of data with neural networks, G. Hinton and R. Salakhutdinov. A fast learning algorithm for deep belief nets (2006), G. Hinton et al. Gradient-based learning applied to document recognition (1998), Y. LeCun et al. Long short-term memory (1997), S. Hochreiter and J. Schmidhuber.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值