DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index.ckpt.data文件)

Posted 一个处女座的程序猿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index.ckpt.data文件)相关的知识,希望对你有一定的参考价值。

DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index、.ckpt.data文件)

目录

基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index、.ckpt.data文件)

#1、定义数据集

# 2、数据集预处理

# 2.1、数据集切分

# 2.2、数据维度转换

# 2.3、训练集、测试集进行MinMax归一化

# 2.4、依次构建train、test的时序性数据集矩阵

# (1)、for循环构建train时序性数据集矩阵

# (2)、for循环构建test时序性数据集矩阵

# 3、模构建GRU模型

# 3.1、模型构建

# 3.2、模型编译并定义优化器、损失函数

# 3.3、模型训练并保存checkpoint文件

# 使入模数据维度标准化

# 创建并保存weights.tx权重文件

# 模型训练过程可视化:绘制loss

epoch=5

# 3.4、模型评估

# 对真实、预测数据进行MinMax反归一化还原

# 画出真实数据和预测数据的对比曲线

# 输出模型评估指标

# 保存预测结果


相关文章
DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index、.ckpt.data文件)

基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index、.ckpt.data文件)

#1、定义数据集

# 数据集下载:http://quotes.money.163.com/trade/lsjysj_600519.html

日期股票代码名称收盘价最高价最低价开盘价前收盘涨跌额涨跌幅换手率成交量成交金额总市值流通市值
2022/6/27'600519贵州茅台2010.552049.942000.32019.942009.011.540.07670.3193401151781244489002.53E+122.53E+12
2022/6/24'600519贵州茅台2009.012020196519701957.151.912.65240.3155396346579211997922.52E+122.52E+12
2022/6/23'600519贵州茅台1957.11965.0419401942.7193621.11.08990.2137268435252398604432.46E+122.46E+12
2022/6/22'600519贵州茅台19361958193219551945.74-9.74-0.50060.1564196466538137752942.43E+122.43E+12
2022/6/21'600519贵州茅台1945.741966.99192819491942.023.720.19160.1888237170246178051272.44E+122.44E+12
2022/6/20'600519贵州茅台1942.021970193019501951-8.98-0.46030.2784349747868027924592.44E+122.44E+12
2022/6/17'600519贵州茅台195119521878.091878.091877743.94250.4023505416197495309162.45E+122.45E+12
2022/6/16'600519贵州茅台18771907.631875.331894.591875.11.90.10130.214268867050876053912.36E+122.36E+12
2022/6/15'600519贵州茅台1875.119051862.99187018714.10.21910.268336636263548691002.36E+122.36E+12
2022/6/14'600519贵州茅台18711875.42183218341856150.80820.2342294162354679493482.35E+122.35E+12
2022/6/13'600519贵州茅台185618921848.0818901900.6-44.6-2.34660.2926367551868472489952.33E+122.33E+12
2022/6/10'600519贵州茅台1900.6190718351845.01185347.62.56880.3769473446288824625982.39E+122.39E+12
2022/6/9'600519贵州茅台18531888.35184918721865.6-12.6-0.67540.2096263290248970666222.33E+122.33E+12
2022/6/8'600519贵州茅台1865.61882182518251817.947.72.62390.3531443538182369538462.34E+122.34E+12
2022/6/7'600519贵州茅台1817.918251770.311784.14178829.91.67230.279350485963560310092.28E+122.28E+12
2022/6/6'600519贵州茅台1788179517581790178620.1120.2925367412665353293522.25E+122.25E+12
2022/6/2'600519贵州茅台17861795.817801787.971788.25-2.25-0.12580.1347169147330197180322.24E+122.24E+12
2022/6/1'600519贵州茅台1788.251814.78177918021804.03-15.78-0.87470.1732217600138978589992.25E+122.25E+12
2022/5/31'600519贵州茅台1804.031814.91766.981774.771778.4125.621.44060.3244407508273292010582.27E+122.27E+12
2022/5/30'600519贵州茅台1778.411790.55176617661755.1623.251.32470.2744344656961356313042.23E+122.23E+12

# 2、数据集预处理

# 2.1、数据集切分

training_set 
 [2019.94 1970.   1942.7  ...   26.07   25.92   26.5 ]
test_set 
 [26.5   0.   25.69 25.6  26.3  25.92 26.   26.24 26.48 26.   25.8  25.8
 25.98 25.78 26.05 26.13 27.2  26.75 26.95 26.7  26.22 26.08 26.03 26.25
 26.5  26.6  27.11 27.1  27.45 26.97 26.79 27.5  27.91 27.78 27.6  27.9
 27.68 27.7  28.   28.15 28.12 28.36 27.98 28.4  28.68 28.97 28.8  28.99
 28.75 29.11 29.01 29.   29.46 30.   30.3  30.35 30.52 30.63 30.4  30.45
 30.56 30.55 30.89 30.73 31.15 31.15 31.   31.   30.59 30.79 30.5  30.98
 30.98 30.7  30.8  31.21 31.42 31.43 31.32 31.44 31.3  31.28 31.52 31.68
 32.2  32.5  32.61 36.3  36.45 36.68 36.37 36.05 35.95 35.68 36.01 35.99
 35.63 36.12 36.18 36.18 36.06 36.68 36.75 36.8  37.08 36.7  36.9  37.28
 39.04 35.   34.98 34.9  34.7  34.55 34.9  35.1  34.8  34.75 35.   34.8
 34.38 34.5  34.9  34.9  35.   34.88 35.21 35.2  35.   35.01 35.88 35.1
 35.54 34.99 34.89 35.25 35.68 35.4  35.57 36.05 36.   36.31 36.48 36.2
 35.5  35.1  35.5  36.19 36.   36.39 37.   38.5  37.88 38.46 37.62 37.49
 37.43 37.   37.3  37.78 36.97 37.02 37.61 37.16 38.   38.01 38.15 38.7
 38.49 38.92 39.3  38.8  38.1  38.12 38.02 38.11 38.31 39.45 39.69 38.55
 38.2  38.8  38.06 37.35 37.95 38.   37.85 37.99 37.6  37.18 37.86 37.93
 37.18 37.5  36.   35.6  35.2  37.   37.24 37.36 36.65 35.8  36.3  34.8
 36.2  36.48 35.98 35.7  37.01 36.98 36.5  37.   37.15 38.72 37.67 37.3
 37.22 36.54 36.45 35.99 34.7  35.9  35.9  35.48 35.11 35.02 35.61 35.6
 36.   36.   36.1  35.9  37.   36.25 35.35 34.83 35.01 35.05 34.58 35.
 35.01 35.22 35.48 35.2  34.15 36.2  33.65 33.64 33.28 34.4  33.7  33.35
 35.   34.8  35.   35.28 35.05 35.   35.25 34.88 34.7  35.7  36.78 36.
 33.3  34.   34.2  34.79 35.13 35.9  35.9  36.01 37.3  36.6  37.   36.9
 36.08 36.11 36.28 36.06 36.28 36.9  36.3  35.88 36.08 36.01 36.01 35.33
 36.8  35.4  36.5  37.35 37.61 37.01 37.2  37.15 36.28 36.98 34.99 34.51]

# 2.2、数据维度转换

进行MinMaxScaler之前,需要将数据从(4754,)→(4754, 1)

before reshape <class 'numpy.ndarray'> (4752,) (300,)
after reshape <class 'numpy.ndarray'> (4752, 1) (300, 1)

# 2.3、训练集、测试集进行MinMax归一化

# 2.4、依次构建train、test的时序性数据集矩阵

# (1)、for循环构建train时序性数据集矩阵

# 提取训练集中连续X_num=60天的开盘价,作为输入特征x_train;以第61天的数据作为label,for循环共构建4752-300-60=4392组数据

01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
00.780508350.7612114470.7506626790.7554154210.753097010.7534834120.7256972620.7320728910.7225712720.7086608090.7302993070.7129150920.7233440750.7051831930.6893948180.6916591320.6908747360.6962959530.6857742330.682385490.6800632150.6804534810.6821034170.6901135250.6955231490.6800632150.6742710530.6853453270.6838847290.6943639440.6877951140.6773622670.6781350710.6646110090.6877951140.7013153120.7071152020.7094336120.6928183370.682818260.6581696920.6762030620.6812262850.6917364120.6961761680.6955231490.6882317480.6963732330.6908863280.6827718920.6680886250.6839310970.6831582930.6792942760.6773622670.6684518430.6646110090.6561101710.6420065070.627902843
10.7612114470.7506626790.7554154210.753097010.7534834120.7256972620.7320728910.7225712720.7086608090.7302993070.7129150920.7233440750.7051831930.6893948180.6916591320.6908747360.6962959530.6857742330.682385490.6800632150.6804534810.6821034170.6901135250.6955231490.6800632150.6742710530.6853453270.6838847290.6943639440.6877951140.6773622670.6781350710.6646110090.6877951140.7013153120.7071152020.7094336120.6928183370.682818260.6581696920.6762030620.6812262850.6917364120.6961761680.6955231490.6882317480.6963732330.6908863280.6827718920.6680886250.6839310970.6831582930.6792942760.6773622670.6684518430.6646110090.6561101710.6420065070.6279028430.661519795
20.7506626790.7554154210.753097010.7534834120.7256972620.7320728910.7225712720.7086608090.7302993070.7129150920.7233440750.7051831930.6893948180.6916591320.6908747360.6962959530.6857742330.682385490.6800632150.6804534810.6821034170.6901135250.6955231490.6800632150.6742710530.6853453270.6838847290.6943639440.6877951140.6773622670.6781350710.6646110090.6877951140.7013153120.7071152020.7094336120.6928183370.682818260.6581696920.6762030620.6812262850.6917364120.6961761680.6955231490.6882317480.6963732330.6908863280.6827718920.6680886250.6839310970.6831582930.6792942760.6773622670.6684518430.6646110090.6561101710.6420065070.6279028430.6615197950.671566241
30.7554154210.753097010.7534834120.7256972620.7320728910.7225712720.7086608090.7302993070.7129150920.7233440750.7051831930.6893948180.6916591320.6908747360.6962959530.6857742330.682385490.6800632150.6804534810.6821034170.6901135250.6955231490.6800632150.6742710530.6853453270.6838847290.6943639440.6877951140.6773622670.6781350710.6646110090.6877951140.7013153120.7071152020.7094336120.6928183370.682818260.6581696920.6762030620.6812262850.6917364120.6961761680.6955231490.6882317480.6963732330.6908863280.6827718920.6680886250.6839310970.6831582930.6792942760.6773622670.6684518430.6646110090.6561101710.6420065070.6279028430.6615197950.6715662410.658814983
40.753097010.753483

以上是关于DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index.ckpt.data文件)的主要内容,如果未能解决你的问题,请参考以下文章

DL之GRU:基于2022年6月最新上证指数数据集结合Pytorch框架利用GRU算法预测最新股票上证指数实现回归预测

TF之LSTM/GRU:基于tensorflow框架对boston房价数据集分别利用LSTMGRU算法(batch_size调优对比)实现房价回归预测案例

学习DL框架的未来发展,TensorFlow/MXNet/Torch, 选哪个?

tensorflow js加载gru模型

DeepLearning4J 中的 GRU

将 GRU 层从 PyTorch 转换为 TensorFlow

(c)2006-2024 SYSTEM All Rights Reserved IT常识