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

本文主要是介绍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.825.98 25.78 26.05 26.13 27.2  26.75 26.95 26.7  26.22 26.08 26.03 26.2526.5  26.6  27.11 27.1  27.45 26.97 26.79 27.5  27.91 27.78 27.6  27.927.68 27.7  28.   28.15 28.12 28.36 27.98 28.4  28.68 28.97 28.8  28.9928.75 29.11 29.01 29.   29.46 30.   30.3  30.35 30.52 30.63 30.4  30.4530.56 30.55 30.89 30.73 31.15 31.15 31.   31.   30.59 30.79 30.5  30.9830.98 30.7  30.8  31.21 31.42 31.43 31.32 31.44 31.3  31.28 31.52 31.6832.2  32.5  32.61 36.3  36.45 36.68 36.37 36.05 35.95 35.68 36.01 35.9935.63 36.12 36.18 36.18 36.06 36.68 36.75 36.8  37.08 36.7  36.9  37.2839.04 35.   34.98 34.9  34.7  34.55 34.9  35.1  34.8  34.75 35.   34.834.38 34.5  34.9  34.9  35.   34.88 35.21 35.2  35.   35.01 35.88 35.135.54 34.99 34.89 35.25 35.68 35.4  35.57 36.05 36.   36.31 36.48 36.235.5  35.1  35.5  36.19 36.   36.39 37.   38.5  37.88 38.46 37.62 37.4937.43 37.   37.3  37.78 36.97 37.02 37.61 37.16 38.   38.01 38.15 38.738.49 38.92 39.3  38.8  38.1  38.12 38.02 38.11 38.31 39.45 39.69 38.5538.2  38.8  38.06 37.35 37.95 38.   37.85 37.99 37.6  37.18 37.86 37.9337.18 37.5  36.   35.6  35.2  37.   37.24 37.36 36.65 35.8  36.3  34.836.2  36.48 35.98 35.7  37.01 36.98 36.5  37.   37.15 38.72 37.67 37.337.22 36.54 36.45 35.99 34.7  35.9  35.9  35.48 35.11 35.02 35.61 35.636.   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.3535.   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.936.08 36.11 36.28 36.06 36.28 36.9  36.3  35.88 36.08 36.01 36.01 35.3336.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.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.6588149830.666110248
50.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.6588149830.6661102480.666156616
60.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.6588149830.6661102480.6661566160.663838206
70.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.6588149830.6661102480.6661566160.6638382060.664611009
80.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.6588149830.6661102480.6661566160.6638382060.6646110090.631380459
90.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.637562887
100.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.668475027
110.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.68238549
120.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.698614363
130.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.681651327
140.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.680059351
150.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.6800593510.68014436
160.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.6800593510.680144360.6847039
170.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.6800593510.680144360.68470390.713220349
180.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.6800593510.680144360.68470390.7132203490.710979219
190.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.6588149830.6661102480.6661566160.6638382060.6646110090.6313804590.6375628870.6684750270.682385490.6986143630.6816513270.6800593510.680144360.68470390.7132203490.7109792190.696295953

# 依次对x_train、y_train打乱数据并转为array格式

01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
00.0767393870.0782849940.0772842140.076511410.0743552890.0741427680.0735631650.0734704290.0728212740.0744209770.0734588370.0741195840.0731613070.0753483410.0734163320.0683003730.0647068370.0699387170.0740036630.0776010630.0771837490.0799774340.0803792920.0813375680.081723970.0811405030.0820330910.0799890260.0801744990.0796876330.0822765250.080858430.0792123590.0798692420.0806922770.0802865560.0772262540.083849180.0852015860.0842317170.0850083850.0856845880.0877711570.0884860010.0970873040.0956344330.0985324460.0996916510.099305250.0915231180.0884860010.0966004370.1035363490.0985324460.0986483670.0985324460.0953021280.0959706030.0966081650.101044058
10.4493852350.4497716370.4539988720.4559540650.4462940210.4470668240.4447484140.4435892090.4283263390.4227235140.4184730950.4119042650.4324685660.4382955050.4424300030.4422368020.4362475750.4408071160.4404979950.4404941310.4347019680.4269739330.428519540.4316107540.4300651470.4269739330.4146052130.4134885120.4076538460.4099722560.4056600130.3972209990.398001530.3926460020.3903855520.3780941120.3684340680.3668884610.3597400290.3651496530.3647632520.3773251730.3767417060.3773213090.3717300750.3717068910.3655244630.3702926610.3718344040.370945680.3690136710.3715252820.3740368940.3769155870.3739596130.3791760370.3825222760.3790330680.3784032330.384489061
20.0199615140.0202010830.0196292090.0198958260.0189336860.0187404850.0184313630.0182033860.0181608820.0182188420.0185936520.0190496060.0173107980.0173687590.0161631850.0156492710.0171948780.0172335180.0172528380.0170016770.017581280.0185086440.0185704680.0186979810.018937550.018937550.0185472840.0192775830.0189336860.0187327570.0187443490.0187404850.0195905690.0197064890.0202860920.0202088120.020409740.0200465230.0200890270.0189723260.0186747970.0180063220.0179599530.0183540830.0188100370.0191268870.0188950460.0186632050.0186322920.0192428070.0193510.019783770.0193857760.0193973680.0189220940.0185781960.018168610.0185472840.0189684620.018276803
300.0343897560.0345829570.0323688750.0347684290.0320288410.0291153720.026468520000000000000000000000000000000000000.0226856470.0225465420.0219785320.0223262930.0226663270.0222760610.02299090400.0223262930.0187018450.0192234870.0191925750.0183154430.0183734030.0176276480.017391943
40.1010440580.0966004370.092659140.0950045980.0977673710.0981305880.1000780530.1031615390.1012836270.1004644550.0987797430.1023964640.0971839040.0997341560.1016159320.1024660160.1045216730.1019868780.1004683190.1063570820.1103254280.1107427410.1043284720.1003408060.0989188480.0973732410.0931421420.0946684290.0971452640.0990154480.0980687640.099382530.097180040.0951011990.0946684290.0942742990.0973732410.0976282660.0970447990.0950934710.0981460440.0995293630.0973268730.1020100620.103864790.092736420.0888724020.0923113780.0805840850.0807966060.0788259570.0778792730.0772764860.079011430.0782463540.0760631840.0749619390.0757192870.0757463350.075997496
50.0736906780.0737447740.0749889880.0762563850.0795910320.0803715640.0819133070.0765075460.0762409290.0763143460.0747107780.0757308790.0763143460.0741466320.077222390.0765075460.0789032370.0784395550.0836057470.0793089590.0784279630.0774851430.0741891360.0689263440.0675739380.0661133390.0643552110.0679680680.0718668610.0703212540.0678328270.0703212540.0643745310.0632153260.0633660230.0638722090.0633505670.0629834850.0635708160.0630607660.0636558240.0648768540.0652052950.0667702220.0653018960.0647145650.0647609330.061862920.062372970.061824280.0612524050.062218410.064142690.0648420780.0672339040.0653018960.0643590750.0658428580.0651434710.064181331
60.0190496060.0173107980.0173687590.0161631850.0156492710.0171948780.0172335180.0172528380.0170016770.017581280.0185086440.0185704680.0186979810.018937550.018937550.0185472840.0192775830.0189336860.0187327570.0187443490.0187404850.0195905690.0197064890.0202860920.0202088120.020409740.0200465230.0200890270.0189723260.0186747970.0180063220.0179599530.0183540830.0188100370.0191268870.0188950460.0186632050.0186322920.0192428070.0193510.019783770.0193857760.0193973680.0189220940.0185781960.018168610.0185472840.0189684620.0182768030.0181608820.0189336860.0188950460.0181608820.0181608820.0183502190.0180449620.0179676810.0182768030.01769720.01761992
70.0875354520.0884821370.0877131970.0901475280.0920061210.0876668290.0869403940.0846219830.0834473220.0846181190.0823422130.0845447030.0819944510.0802826920.079598760.0779063210.0785168360.0787254920.0774967350.077280350.0792084950.0791350780.0782772660.0780531530.0780917940.0763066180.0771837490.0772726220.0776628880.0784395550.0784820590.0777672160.0799851620.0776667520.0765075460.0791157580.0761636490.0769325880.0777053920.0785013790.0788916450.0807541020.0822185640.0811443670.0842355810.084320590.0850779370.0844751510.0871258670.0869403940.0865462640.0871142740.0876359170.0842355810.0832695770.0828406710.0828483990.0826126940.0812177840.082110372
80.0788259570.079521480.0787486770.0800238020.0831150160.0768939480.077280350.0778213120.07689394800.0714418190.0714727320.0682385490.0674271050.0666658940.0687022310.0676280340.0696295950.0691272730.0685863110.0687795110.0703251180.0718707250.0705183190.0695523150.0709047210.0722841750.0686945030.0664611010.0663104040.0664688290.0690577210.0705183190.0695832270.0710979220.070711520.0743823370.0725701130.0741968640.0745794020.073702270.0730299310.0726628490.0709047210.0687795110.0681999090.0690422650.0710979220.0730260670.0680453480.0676589460.0636944640.0620986250.0566078560.0585514570.0564069270.0562871430.0537137070.0546603920.055641852
90.0963106360.0965270210.0947109330.0945795560.0937487920.0936444640.0938956250.0931150940.0947843490.0923577460.0908044110.0919636160.0898268150.0884860010.0882193830.0892201640.0925586750.0930416770.0946684290.0931228220.0929103010.0933160230.092852340.0933971670.0901088880.090514610.0898384070.09157721500.0842355810.0838453160.0869403940.0884860010.0890656030.0877943420.0896065660.0915463030.0899040950.0887217060.0921259050.0943824910.0954335040.0958276340.0960131070.0969868390.0972959610.0975509860.0961444830.0953021280.0937024240.0939381290.0951243830.0964072370.0963106360.0969404710.0984938060.0966004370.0929721250.0926900520.094857766
100.7723707290.7728421390.786327560.786327560.7728034990.7631164070.7921235870.7998516220.7631434560.7639162590.7554154210.8017681740.7728034990.8095116650.7882595690.8423558140.8419694120.8114436740.8535614650.8918113740.8752540590.9486162950.94713251310.9602083480.9153084650.9030208890.8983840680.8466062330.8307637620.8161655040.8230357270.8119034920.8037156390.8276300440.8442878230.8048748440.799465220.7913507830.7758947130.8010533310.796397190.81723970.8330821720.8361733860.8068068530.8075796570.8276725480.8102844690.7978423330.7689394820.7727957710.7500057960.7225712720.7237304770.7058014360.6966784910.7024783810.7333866570.714831645
110.30912140.3006205610.2998670780.3013933650.3052496540.3044845790.3039049760.2907093560.2902379460.2821698780.280999080.2854736130.2774364560.2751180460.278209260.2859372950.2840902940.2874829020.2797510030.2840516540.2859372950.2882557050.2797548670.2777030730.2718336310.2739897530.2697200130.2550058350.2592678460.2573435650.2550251550.2647817990.2673900110.2662308050.2612075830.2573474290.2631395910.2549671940.2592755740.2646851980.2629773030.2699016220.2720268320.2743452420.2723359530.269360660.2635259930.2619803860.262753190.26507160.2636032740.2704696330.2793684650.2735724390.2708676260.2874829020.2898438160.2898013120.287471310.288873948
120.0610514760.0613605980.0612562690.0586094170.0579602620.0579216220.0581534630.0580839110.0572840590.0584200810.0590730990.0598845430.0590421870.0581186870.0575274920.0571101790.0564146550.0585823690.0572840590.0571101790.0556727640.0548690480.055255450.0535668750.0538180360.0552284020.0551008890.0541348850.054370590.0533929940.0536325630.0527477030.052542910.0514107530.0505799890.0504254280.0500003860.0505181650.0505413490.0496835370.0491155260.0493048630.048647980.0488798210.0488991410.0494014640.048686620.0496564890.0503095080.0501549470.0509702550.0510050310.0514918970.0511595920.0525545020.0537871240.0547028960.0546372070.0541812530.054505831
130.1188571780.1209051070.1198425030.1192513080.1219097520.1226825560.1225357230.1221377290.1248193570.1220102160.1194097330.1211485410.1220256730.1158432450.1140001080.1108973020.1109745820.1120642350.1111098230.110905030.1062604810.1063686740.1081808980.1057852070.1070487410.1081036170.1057195190.1062063850.1046028180.1034436120.1056229180.1068014440.1068400840.1089652930.1031692670.1016275240.1025510240.0989188480.097180040.097651450.0973693770.0983315170.0983044690.0964922450.0953794080.0947302530.0962449480.0969907030.0969327430.098911120.0981537720.0975084820.0964072370.096650670.0994250340.0991120490.1004644550.0968129580.0955919290.094989142
140.0880995990.0892588040.0893051720.090591890.0907271310.0875199960.0873190670.0873267950.0837293950.0827865750.0820910520.0819905870.0818089780.0804874840.0826049660.0813027920.0822417480.0821103720.0821103720.0807000050.0792123590.0808661580.0801976830.0794519280.0757733830.0777285760.0775894710.0768939480.0812293760.0815771370.0801783630.0789496050.0802942840.0801976830.0802942840.0775856070.0769094040.0778947290.077318990.0773267180.0752285570.0746566820.0752401490.0768939480.0776087910.0782965870.0786404840.0776667520.0770601010.076808940.0750314920.0743900650.0744828010.0741079920.0745600820.0749155710.0747764670.0744712090.0744557530.073223132
150.0092736420.009377970.0092736420.0091113530.0091152170.0090881690.0090920330.0091770420.0091886340.0091499930.0092350020.0090418010.0091036250.0089838410.0089606570.0090031610.0089220160.0089220160.008887240.0090031610.0089181520.0090340730.008829280.008790640.008887240.0089181520.008809960.0088833760.008887240.008906560.008887240.0090031610.0091461290.0089799770.0087945040.0087635920.0086940390.0085394790.0082419490.0081917170.008299910.0083462780.0084274220.0082883180.0082651330.0082612690.0082921820.0083694620.0084042380.008338550.0083462780.0081646690.0081917170.0081608050.0081608050.0081530770.0081801250.0081917170.0081762610.008075797
160.8752540590.9486162950.94713251310.9602083480.9153084650.9030208890.8983840680.8466062330.8307637620.8161655040.8230357270.8119034920.8037156390.8276300440.8442878230.8048748440.799465220.7913507830.7758947130.8010533310.796397190.81723970.8330821720.8361733860.8068068530.8075796570.8276725480.8102844690.7978423330.7689394820.7727957710.7500057960.7225712720.7237304770.7058014360.6966784910.7024783810.7333866570.7148316450.7109792190.7155426240.7131044290.7073084030.7084676080.7062535260.7089622020.7109792190.7210063450.7013191760.6965664340.6769758650.6715701050.6746574550.666929420.6704070360.6695028560.666929420.6806466820.683927233
170.1735407540.1719371870.173123440.1738807870.1709827740.1738807870.1741976370.1733823290.1750013520.1708861740.1696458240.16598660.1642400640.1657663510.1621341740.1596302910.15981190.1578064750.1578064750.1562763240.160812680.1608204080.1602137570.1588111190.159042960.1630576740.1605615190.1618443730.1564154280.1548002690.1603567260.1569138870.1557199050.152474130.1510830840.1543404510.1509980760.148876730.1499431990.1522422890.1518520240.1503141450.1490196990.1492283560.147991870.1472229310.1468133450.1491626670.1515931340.1514810780.1509014750.1493635960.1470258660.1441664930.1455034430.1427754460.143567570.1429879670.1429377350.141809442
180.2886227870.2831088340.2843916880.2865168970.2855508930.2868762510.2925061240.2906900360.2868260190.2774364560.2743452420.2816868750.2782208520.2731860370.2704812250.2673900110.2742525060.2838198130.2752339660.2758908490.2905741160.2957171230.295983740.2913469190.2956823470.2863236960.2971429450.2987658330.3052573820.30912140.3006205610.2998670780.3013933650.3052496540.3044845790.3039049760.2907093560.2902379460.2821698780.280999080.2854736130.2774364560.2751180460.278209260.2859372950.2840902940.2874829020.2797510030.2840516540.2859372950.2882557050.2797548670.2777030730.2718336310.2739897530.2697200130.2550058350.2592678460.2573435650.255025155
190.7157319610.7202644530.7264352890.7167752460.7114042610.7082744070.6955231490.7295265030.7303379470.7453419270.7225712720.7210256650.7107898820.7041862770.7025479330.6990007650.7140704330.6762030620.6290620480.6329260660.6409748140.6259708340.6194020050.6375628870.6410405030.6433589130.6314113710.6282892450.6414269040.6418248980.6371764850.6221145450.6309901930.6024003280.6143015020.6201748080.613992380.6433550490.6366509790.6085827560.5942395230.6009204090.6268286460.6277714670.6568829740.6553373670.6530189570.669247830.6877989780.6568829740.6379492890.6526325550.6541317940.6700438180.6684750270.6429725110.6665430180.6993910310.658042180.696682355

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

# 测试集:csv表格中后300天数据,for循环共构建300-60=240组数据。

# 将df格式数据转为array格式

# 3、模构建GRU模型

# 3.1、模型构建

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

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

# 使入模数据维度标准化

x_train要reshape成符合RNN输入要求:[样本数, 循环核时间展开步数, 每个时间步输入特征个数]

before x_train.shape[0]: 4692
after x_train.shape: (4692, 60, 1)

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

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
gru (GRU)                    (None, 60, 80)            19680     
_________________________________________________________________
dropout (Dropout)            (None, 60, 80)            0         
_________________________________________________________________
gru_1 (GRU)                  (None, 100)               54300     
_________________________________________________________________
dropout_1 (Dropout)          (None, 100)               0         
_________________________________________________________________
dense (Dense)                (None, 1)                 101       
=================================================================
Total params: 74,081
Trainable params: 74,081
Non-trainable params: 0
_________________________________________________________________

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

epoch=5

# 3.4、模型评估

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

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

# 输出模型评估指标

R2: 0.5177
MSE: 1.8693
RMSE: 1.3672
MAE: 1.2081

None
R2: 0.8342
MSE: 0.6269
RMSE: 0.7918
MAE: 0.5756

# 保存预测结果

这篇关于DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index、.ckpt.data文件)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/418680

相关文章

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

不懂推荐算法也能设计推荐系统

本文以商业化应用推荐为例,告诉我们不懂推荐算法的产品,也能从产品侧出发, 设计出一款不错的推荐系统。 相信很多新手产品,看到算法二字,多是懵圈的。 什么排序算法、最短路径等都是相对传统的算法(注:传统是指科班出身的产品都会接触过)。但对于推荐算法,多数产品对着网上搜到的资源,都会无从下手。特别当某些推荐算法 和 “AI”扯上关系后,更是加大了理解的难度。 但,不了解推荐算法,就无法做推荐系

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

关于数据埋点,你需要了解这些基本知识

产品汪每天都在和数据打交道,你知道数据来自哪里吗? 移动app端内的用户行为数据大多来自埋点,了解一些埋点知识,能和数据分析师、技术侃大山,参与到前期的数据采集,更重要是让最终的埋点数据能为我所用,否则可怜巴巴等上几个月是常有的事。   埋点类型 根据埋点方式,可以区分为: 手动埋点半自动埋点全自动埋点 秉承“任何事物都有两面性”的道理:自动程度高的,能解决通用统计,便于统一化管理,但个性化定

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

异构存储(冷热数据分离)

异构存储主要解决不同的数据,存储在不同类型的硬盘中,达到最佳性能的问题。 异构存储Shell操作 (1)查看当前有哪些存储策略可以用 [lytfly@hadoop102 hadoop-3.1.4]$ hdfs storagepolicies -listPolicies (2)为指定路径(数据存储目录)设置指定的存储策略 hdfs storagepolicies -setStoragePo

Hadoop集群数据均衡之磁盘间数据均衡

生产环境,由于硬盘空间不足,往往需要增加一块硬盘。刚加载的硬盘没有数据时,可以执行磁盘数据均衡命令。(Hadoop3.x新特性) plan后面带的节点的名字必须是已经存在的,并且是需要均衡的节点。 如果节点不存在,会报如下错误: 如果节点只有一个硬盘的话,不会创建均衡计划: (1)生成均衡计划 hdfs diskbalancer -plan hadoop102 (2)执行均衡计划 hd

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

康拓展开(hash算法中会用到)

康拓展开是一个全排列到一个自然数的双射(也就是某个全排列与某个自然数一一对应) 公式: X=a[n]*(n-1)!+a[n-1]*(n-2)!+...+a[i]*(i-1)!+...+a[1]*0! 其中,a[i]为整数,并且0<=a[i]<i,1<=i<=n。(a[i]在不同应用中的含义不同); 典型应用: 计算当前排列在所有由小到大全排列中的顺序,也就是说求当前排列是第

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个