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文件)
相关文章
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.55 | 2049.94 | 2000.3 | 2019.94 | 2009.01 | 1.54 | 0.0767 | 0.3193 | 4011517 | 8124448900 | 2.53E+12 | 2.53E+12 |
2022/6/24 | '600519 | 贵州茅台 | 2009.01 | 2020 | 1965 | 1970 | 1957.1 | 51.91 | 2.6524 | 0.3155 | 3963465 | 7921199792 | 2.52E+12 | 2.52E+12 |
2022/6/23 | '600519 | 贵州茅台 | 1957.1 | 1965.04 | 1940 | 1942.7 | 1936 | 21.1 | 1.0899 | 0.2137 | 2684352 | 5239860443 | 2.46E+12 | 2.46E+12 |
2022/6/22 | '600519 | 贵州茅台 | 1936 | 1958 | 1932 | 1955 | 1945.74 | -9.74 | -0.5006 | 0.1564 | 1964665 | 3813775294 | 2.43E+12 | 2.43E+12 |
2022/6/21 | '600519 | 贵州茅台 | 1945.74 | 1966.99 | 1928 | 1949 | 1942.02 | 3.72 | 0.1916 | 0.1888 | 2371702 | 4617805127 | 2.44E+12 | 2.44E+12 |
2022/6/20 | '600519 | 贵州茅台 | 1942.02 | 1970 | 1930 | 1950 | 1951 | -8.98 | -0.4603 | 0.2784 | 3497478 | 6802792459 | 2.44E+12 | 2.44E+12 |
2022/6/17 | '600519 | 贵州茅台 | 1951 | 1952 | 1878.09 | 1878.09 | 1877 | 74 | 3.9425 | 0.4023 | 5054161 | 9749530916 | 2.45E+12 | 2.45E+12 |
2022/6/16 | '600519 | 贵州茅台 | 1877 | 1907.63 | 1875.33 | 1894.59 | 1875.1 | 1.9 | 0.1013 | 0.214 | 2688670 | 5087605391 | 2.36E+12 | 2.36E+12 |
2022/6/15 | '600519 | 贵州茅台 | 1875.1 | 1905 | 1862.99 | 1870 | 1871 | 4.1 | 0.2191 | 0.268 | 3366362 | 6354869100 | 2.36E+12 | 2.36E+12 |
2022/6/14 | '600519 | 贵州茅台 | 1871 | 1875.42 | 1832 | 1834 | 1856 | 15 | 0.8082 | 0.2342 | 2941623 | 5467949348 | 2.35E+12 | 2.35E+12 |
2022/6/13 | '600519 | 贵州茅台 | 1856 | 1892 | 1848.08 | 1890 | 1900.6 | -44.6 | -2.3466 | 0.2926 | 3675518 | 6847248995 | 2.33E+12 | 2.33E+12 |
2022/6/10 | '600519 | 贵州茅台 | 1900.6 | 1907 | 1835 | 1845.01 | 1853 | 47.6 | 2.5688 | 0.3769 | 4734462 | 8882462598 | 2.39E+12 | 2.39E+12 |
2022/6/9 | '600519 | 贵州茅台 | 1853 | 1888.35 | 1849 | 1872 | 1865.6 | -12.6 | -0.6754 | 0.2096 | 2632902 | 4897066622 | 2.33E+12 | 2.33E+12 |
2022/6/8 | '600519 | 贵州茅台 | 1865.6 | 1882 | 1825 | 1825 | 1817.9 | 47.7 | 2.6239 | 0.3531 | 4435381 | 8236953846 | 2.34E+12 | 2.34E+12 |
2022/6/7 | '600519 | 贵州茅台 | 1817.9 | 1825 | 1770.31 | 1784.14 | 1788 | 29.9 | 1.6723 | 0.279 | 3504859 | 6356031009 | 2.28E+12 | 2.28E+12 |
2022/6/6 | '600519 | 贵州茅台 | 1788 | 1795 | 1758 | 1790 | 1786 | 2 | 0.112 | 0.2925 | 3674126 | 6535329352 | 2.25E+12 | 2.25E+12 |
2022/6/2 | '600519 | 贵州茅台 | 1786 | 1795.8 | 1780 | 1787.97 | 1788.25 | -2.25 | -0.1258 | 0.1347 | 1691473 | 3019718032 | 2.24E+12 | 2.24E+12 |
2022/6/1 | '600519 | 贵州茅台 | 1788.25 | 1814.78 | 1779 | 1802 | 1804.03 | -15.78 | -0.8747 | 0.1732 | 2176001 | 3897858999 | 2.25E+12 | 2.25E+12 |
2022/5/31 | '600519 | 贵州茅台 | 1804.03 | 1814.9 | 1766.98 | 1774.77 | 1778.41 | 25.62 | 1.4406 | 0.3244 | 4075082 | 7329201058 | 2.27E+12 | 2.27E+12 |
2022/5/30 | '600519 | 贵州茅台 | 1778.41 | 1790.55 | 1766 | 1766 | 1755.16 | 23.25 | 1.3247 | 0.2744 | 3446569 | 6135631304 | 2.23E+12 | 2.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组数据
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | |
0 | 0.78050835 | 0.761211447 | 0.750662679 | 0.755415421 | 0.75309701 | 0.753483412 | 0.725697262 | 0.732072891 | 0.722571272 | 0.708660809 | 0.730299307 | 0.712915092 | 0.723344075 | 0.705183193 | 0.689394818 | 0.691659132 | 0.690874736 | 0.696295953 | 0.685774233 | 0.68238549 | 0.680063215 | 0.680453481 | 0.682103417 | 0.690113525 | 0.695523149 | 0.680063215 | 0.674271053 | 0.685345327 | 0.683884729 | 0.694363944 | 0.687795114 | 0.677362267 | 0.678135071 | 0.664611009 | 0.687795114 | 0.701315312 | 0.707115202 | 0.709433612 | 0.692818337 | 0.68281826 | 0.658169692 | 0.676203062 | 0.681226285 | 0.691736412 | 0.696176168 | 0.695523149 | 0.688231748 | 0.696373233 | 0.690886328 | 0.682771892 | 0.668088625 | 0.683931097 | 0.683158293 | 0.679294276 | 0.677362267 | 0.668451843 | 0.664611009 | 0.656110171 | 0.642006507 | 0.627902843 |
1 | 0.761211447 | 0.750662679 | 0.755415421 | 0.75309701 | 0.753483412 | 0.725697262 | 0.732072891 | 0.722571272 | 0.708660809 | 0.730299307 | 0.712915092 | 0.723344075 | 0.705183193 | 0.689394818 | 0.691659132 | 0.690874736 | 0.696295953 | 0.685774233 | 0.68238549 | 0.680063215 | 0.680453481 | 0.682103417 | 0.690113525 | 0.695523149 | 0.680063215 | 0.674271053 | 0.685345327 | 0.683884729 | 0.694363944 | 0.687795114 | 0.677362267 | 0.678135071 | 0.664611009 | 0.687795114 | 0.701315312 | 0.707115202 | 0.709433612 | 0.692818337 | 0.68281826 | 0.658169692 | 0.676203062 | 0.681226285 | 0.691736412 | 0.696176168 | 0.695523149 | 0.688231748 | 0.696373233 | 0.690886328 | 0.682771892 | 0.668088625 | 0.683931097 | 0.683158293 | 0.679294276 | 0.677362267 | 0.668451843 | 0.664611009 | 0.656110171 | 0.642006507 | 0.627902843 | 0.661519795 |
2 | 0.750662679 | 0.755415421 | 0.75309701 | 0.753483412 | 0.725697262 | 0.732072891 | 0.722571272 | 0.708660809 | 0.730299307 | 0.712915092 | 0.723344075 | 0.705183193 | 0.689394818 | 0.691659132 | 0.690874736 | 0.696295953 | 0.685774233 | 0.68238549 | 0.680063215 | 0.680453481 | 0.682103417 | 0.690113525 | 0.695523149 | 0.680063215 | 0.674271053 | 0.685345327 | 0.683884729 | 0.694363944 | 0.687795114 | 0.677362267 | 0.678135071 | 0.664611009 | 0.687795114 | 0.701315312 | 0.707115202 | 0.709433612 | 0.692818337 | 0.68281826 | 0.658169692 | 0.676203062 | 0.681226285 | 0.691736412 | 0.696176168 | 0.695523149 | 0.688231748 | 0.696373233 | 0.690886328 | 0.682771892 | 0.668088625 | 0.683931097 | 0.683158293 | 0.679294276 | 0.677362267 | 0.668451843 | 0.664611009 | 0.656110171 | 0.642006507 | 0.627902843 | 0.661519795 | 0.671566241 |
3 | 0.755415421 | 0.75309701 | 0.753483412 | 0.725697262 | 0.732072891 | 0.722571272 | 0.708660809 | 0.730299307 | 0.712915092 | 0.723344075 | 0.705183193 | 0.689394818 | 0.691659132 | 0.690874736 | 0.696295953 | 0.685774233 | 0.68238549 | 0.680063215 | 0.680453481 | 0.682103417 | 0.690113525 | 0.695523149 | 0.680063215 | 0.674271053 | 0.685345327 | 0.683884729 | 0.694363944 | 0.687795114 | 0.677362267 | 0.678135071 | 0.664611009 | 0.687795114 | 0.701315312 | 0.707115202 | 0.709433612 | 0.692818337 | 0.68281826 | 0.658169692 | 0.676203062 | 0.681226285 | 0.691736412 | 0.696176168 | 0.695523149 | 0.688231748 | 0.696373233 | 0.690886328 | 0.682771892 | 0.668088625 | 0.683931097 | 0.683158293 | 0.679294276 | 0.677362267 | 0.668451843 | 0.664611009 | 0.656110171 | 0.642006507 | 0.627902843 | 0.661519795 | 0.671566241 | 0.658814983 |
4 | 0.75309701 | 0.753483 以上是关于DL之GRU(Tensorflow框架):基于茅台股票数据集利用GRU算法实现回归预测(保存模型.ckpt.index.ckpt.data文件)的主要内容,如果未能解决你的问题,请参考以下文章 DL之GRU:基于2022年6月最新上证指数数据集结合Pytorch框架利用GRU算法预测最新股票上证指数实现回归预测 TF之LSTM/GRU:基于tensorflow框架对boston房价数据集分别利用LSTMGRU算法(batch_size调优对比)实现房价回归预测案例 |