Giter VIP home page Giter VIP logo

ssq's Introduction

利用神经网络和LSTM预测双色球(How To predict the China's Union Lotto with Neural Network and LSTM)

2020/12/4更新

因为问的人比较多了,所以提供了适配'tensorflow 2.X'版本的分支.

2019/6/18更新

利用最近几次的双色球结果和奖池情况做预测,训练和测试见ssq4all_v4.pyssq4all_test_v4.py

2018/9/16更新

添加了大乐透的训练测试文件。

2018/5/30更新

根据反馈,修复了一些错误,删除了两个文件。另外,有问题请直接开issue。

2018/3/29更新

尝试用CNN和LSTM做预测。CNN用于提取特征,采用的是resnet。目前最好的结果是五等奖(中4个红号)。

背景(Background)


这个项目是通过结合神经网络和Long Short-Term Memory(LSTM)完成双色球预测。关于双色球的介绍,在此处不在赘述(参见网站)。该项目以真实的双色球开奖结果作为输入(7个数值,其中前6个表示红号,最后一个表示蓝号),输出预测结果(输出仍为7个数值,其中前6个表示红号,最后一个表示蓝号)。目前该项目还处于开发中。

其中,项目核心代码主要借鉴了这个网站 。 截至目前,该项目充分训练后的预测结果中,正确预测的红号数目为0-2个(1个的居多,但鉴于这概率本身就偏高,因此不能算是取得很好的结果),正确预测的蓝号数目为0-1个(0个的居多),考虑到双色球的中奖条件(至少3红号正确或者至少蓝号正确),不建议各位直接根据预测结果去买
预测结果不好有以下几个原因:

  1. 双色球本身是一个随机事件,而我却希望从中找到规律;
  2. 数据集样本数量不够多且无法有效扩大数据集;
  3. 可能我的模型还不够优秀。

如果您有什么好的建议或者有什么问题,请直接发我邮箱([email protected])或者在issue留言也可以;
如果您觉得这项目似乎还有点意思,记得STAR;
当然,如果您真的中奖了,要求不高, STAR。

项目依赖(Requirement)


1.Tensorflow;
2.pyexcel_xls;
3.CUDA.(optional)
该项目的代码可能还需要一些python包但我没列出来,请自行pip一下。

项目文件(File contents)


1. poems : poems文件夹包含3个模型文件,其中model.py是本项目所使用的模型文件;其中resnet.py定义的是resnet模型;
2.ssq.py : 该文件用于训练双色球模型;
3.ssq.xls : 该文件储存了历次双色球的开奖和中奖数据,需要利用宏进行数据更新;
4.ssq_data.py : 读取ssq.xls文件中的数据并变成所需要的形式.
5.ssq_test.py: 以最近一次的双色球开奖结果作为输入,输出模型产生的预测结果;
6.ssq4all.py : 该文件用于训练双色球模型(和ssq.py 功能一样,但用的模型不一样);
7.ssq4all_test.py: 以最近一次的双色球开奖结果作为输入,输出模型产生的预测结果;
6.dlt.xls : 该文件储存了历次双色球的开奖和中奖数据,需要利用宏进行数据更新;
7.dlt4all.py : 该文件用于训练大乐透模型;
8.dlt4all_test.py: 以最近一次的大乐透开奖结果作为输入,输出模型产生的预测结果;

训练及测试(How To Use)


设置好参数,运行ssq.py(建议在控制台运行,这样训练到一半可以直接通过按CTRL+C取消训练并保存结果;这样下次训练时可以从上一次的checkpoint继续训练)。训练后,项目目录下会生成一个model文件夹用于保存模型。然后运行ssq_test.py进行预测就可以了。
该项目在W10, tensorflow 1.4/1.5正常运行。有无GPU均可运行。原则上讲,这项目的模型并不大,且数据量也不大,所以可以直接将所有训练数据作为一个batch进行训练,后续如果需要加深模型,可能要降低batch size。

ssq's People

Contributors

liang-yc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ssq's Issues

input的值

input的值是什么意思呀,大佬,还有个问题,怎么历史数据不会更新点着没用

缺少方法 get_exl_data_v2

问题一
缺少这个方法,
get_exl_data_v2

问题二:
Traceback (most recent call last):
File "ssq4all.py", line 121, in
tf.compat.v1.app.run()
raise ValueError(
ValueError: Cannot feed value of shape (2656, 1, 7, 1) for Tensor 'Placeholder:0', which has shape '(2656, 1, 13, 1)'

中奖过的友友们来!

谁中过奖的,都在这里填一下中奖的时间和金额吧!
让新来的友友们 羡慕一下呢?

ImportError: No module named model

python ssq.py
Traceback (most recent call last):
File "ssq.py", line 24, in
from poems.model import rnn_model
ImportError: No module named model
想問一下這個錯誤怎麼解決?謝謝

python version

使用python的版本是什么,我这边import tensorflow as tf提示ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。

ModuleNotFoundError: No module named 'win_unicode_console'

Traceback (most recent call last):
File "ssq4all_v4.py", line 13, in
import win_unicode_console
ModuleNotFoundError: No module named 'win_unicode_console'
想問一下這個錯誤怎麼解決?謝謝
"ssq4all_v4.py"这个是windows运行还是ubuntu下运行呢?

跑dlt4all.py出错

跑ssq4all.py没问题,跑dlt4all.py出错如下:
Traceback (most recent call last):
File "C:\ssq\dlt\dlt4all.py", line 126, in
tf.compat.v1.app.run()
File "C:\Program Files\Python39\lib\site-packages\tensorflow\python\platform\app.py", line 36, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "C:\Program Files\Python39\lib\site-packages\absl\app.py", line 312, in run
_run_main(main, args)
File "C:\Program Files\Python39\lib\site-packages\absl\app.py", line 258, in _run_main
sys.exit(main(argv))
File "C:\ssq\dlt\dlt4all.py", line 122, in main
run_training()
File "C:\ssq\dlt\dlt4all.py", line 59, in run_training
input_data = tf.compat.v1.placeholder(tf.float32, [FLAGS.batch_size, 1,7,1])
File "C:\Program Files\Python39\lib\site-packages\tensorflow\python\ops\array_ops.py", line 3298, in placeholder
raise RuntimeError("tf.placeholder() is not compatible with "
RuntimeError: tf.placeholder() is not compatible with eager execution.

用的是ty2分支,python3.9

请教一下数据准备问题

ssq_data.py里的get_exl_data方法用来获取数据,想问下红色球的数字都减了1,蓝色球的数字加了32,这样是有什么特殊作用吗?

新配置的环境运行还是报如下错误

D:\python\Anaconda3\python.exe D:/ProgramData/ssq-master/dlt4all.py
2019-10-31 15:03:33.152776: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2019-10-31 15:03:33.152776: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2019-10-31 15:03:33.152776: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2019-10-31 15:03:33.152776: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2019-10-31 15:03:33.155276: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.

restore from the checkpoint D:\ProgramData\ssq-master\dlt_model\poems-0

start training...

2019-10-31 15:03:38.997865: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:1158] Invalid argument: stride must be less than or equal to kernel size
WARNING:tensorflow:Error encountered when serializing LAYER_NAME_UIDS.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
'dict' object has no attribute 'name'

Last epoch were saved, next time will start from epoch 0.

Traceback (most recent call last):
File "D:\python\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1139, in _do_call
return fn(*args)
File "D:\python\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1121, in _run_fn
status, run_metadata)
File "D:\python\Anaconda3\lib\contextlib.py", line 66, in exit
next(self.gen)
File "D:\python\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: stride must be less than or equal to kernel size
[[Node: gradients/conv3_0/AvgPool_grad/AvgPoolGrad = AvgPoolGrad[T=DT_FLOAT, data_format="NHWC", ksize=[1, 1, 1, 1], padding="VALID", strides=[1, 2, 2, 1], _device="/job:localhost/replica:0/task:0/cpu:0"](gradients/conv3_0/AvgPool_grad/Shape, gradients/conv3_0/Pad_grad/Slice_1)]]

麻烦大佬帮我看看日志, 我训练的时候是否启用了GPU在跑??

F:\GitHub\ssq\venv\Scripts\python.exe "D:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\pydevconsole.py" --mode=client --port=2435
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['F:\GitHub\ssq', 'F:/GitHub/ssq'])
PyDev console: starting.
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32

runfile('F:/GitHub/ssq/ssq4all_v4.py', wdir='F:/GitHub/ssq')
2021-05-15 15:22:44.122567: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
WARNING:tensorflow:From F:\GitHub\ssq\poems\resnet.py:69: calling Constant.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
W0515 15:22:48.327268 3008 deprecation.py:537] From F:\GitHub\ssq\poems\resnet.py:69: calling Constant.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
2021-05-15 15:22:48.348672: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-15 15:22:48.357103: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library nvcuda.dll
2021-05-15 15:22:48.432472: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:04:00.0 name: GeForce GTX 760 computeCapability: 3.0
coreClock: 1.0975GHz coreCount: 6 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 179.05GiB/s
2021-05-15 15:22:48.432961: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
2021-05-15 15:22:48.525946: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublas64_11.dll
2021-05-15 15:22:48.526119: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cublasLt64_11.dll
2021-05-15 15:22:48.568220: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cufft64_10.dll
2021-05-15 15:22:48.579939: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library curand64_10.dll
2021-05-15 15:22:48.584193: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2021-05-15 15:22:48.611621: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cusparse64_11.dll
2021-05-15 15:22:48.617375: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudnn64_8.dll
2021-05-15 15:22:48.617576: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1757] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
F:\GitHub\ssq\venv\lib\site-packages\tensorflow\python\keras\layers\legacy_rnn\rnn_cell_impl.py:702: UserWarning: tf.nn.rnn_cell.BasicLSTMCell is deprecated and will be removed in a future version. This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.
warnings.warn("tf.nn.rnn_cell.BasicLSTMCell is deprecated and will be "
WARNING:tensorflow:tf.nn.rnn_cell.MultiRNNCell is deprecated. This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.
W0515 15:22:48.860270 3008 rnn_cell_impl.py:1242] tf.nn.rnn_cell.MultiRNNCell is deprecated. This class is equivalent as tf.keras.layers.StackedRNNCells, and will be replaced by that in Tensorflow 2.0.
WARNING:tensorflow:At least two cells provided to MultiRNNCell are the same object and will share weights.
W0515 15:22:48.860270 3008 rnn_cell_impl.py:1254] At least two cells provided to MultiRNNCell are the same object and will share weights.
WARNING:tensorflow:From F:\GitHub\ssq\poems\model.py:93: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.
Instructions for updating:
Please use keras.layers.RNN(cell), which is equivalent to this API
W0515 15:22:48.942326 3008 deprecation.py:339] From F:\GitHub\ssq\poems\model.py:93: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.
Instructions for updating:
Please use keras.layers.RNN(cell), which is equivalent to this API
F:\GitHub\ssq\venv\lib\site-packages\tensorflow\python\keras\engine\base_layer_v1.py:1727: UserWarning: layer.add_variable is deprecated and will be removed in a future version. Please use layer.add_weight method instead.
warnings.warn('layer.add_variable is deprecated and '
WARNING:tensorflow:From F:\GitHub\ssq\venv\lib\site-packages\tensorflow\python\keras\layers\legacy_rnn\rnn_cell_impl.py:753: calling Zeros.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
W0515 15:22:48.992315 3008 deprecation.py:537] From F:\GitHub\ssq\venv\lib\site-packages\tensorflow\python\keras\layers\legacy_rnn\rnn_cell_impl.py:753: calling Zeros.init (from tensorflow.python.ops.init_ops) with dtype is deprecated and will be removed in a future version.
Instructions for updating:
Call initializer instance with the dtype argument instead of passing it to the constructor
2021-05-15 15:22:50.472322: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-15 15:22:50.472797: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267]
2021-05-15 15:22:50.473007: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-05-15 15:22:50.508668: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:196] None of the MLIR optimization passes are enabled (registered 0 passes)

start training...

till 100000

验证问题

1.训练17721088次后,验证上上一次开奖结果应该得到上一次的开奖结果。电脑配置不行,还没跑完。有谁跑完可以分享一下模型文件
2.(假设开奖结果受到干预)当第T期模型结果和实际开奖结果不一样的时候,应该让它按照实际结果运行一下。就是按照第t期开奖结果重新跑,历史开奖记录都跑一篇
3.(假设开奖结果完全随机)不应该按照开奖顺序跑,应该按照红球从小打大排列的结果跑。按照开奖顺序,则第一个球的概率是三十三分之一。按照从小到大的第一个球的概率是下一个球数减一分之一。这样可以较少运算次数和提高准确率

发现预测的球有重复,是不是哪里算法

昨天晚上执行了模型,执行ssq。发现预测的球有重复,是不是哪里算法。。。我还在学习这个机器学习。所以只能反馈

input: [[ 1 4 10 12 30 32 14]]
output:[14 8 7 26 8 8 10]

结果相差较大

你好,我是在epochs跑到35w左右的时候,相差一千多epochs,预测结果完全不一样,这个正常吗?此时的loss在0.2左右

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.