Giter Club home page Giter Club logo

predict_lottery_ticket's Introduction

双色球+大乐透彩票AI预测

有问题,欢迎联系我(QQ: 270393749,客服群号:246714623)

公众号

avatar

Installing

  • step1,安装anaconda(可参考https://zhuanlan.zhihu.com/p/32925500);

  • step2,创建一个conda环境,conda create -n your_env_name python=3.6;

  • step3,进入创建conda的环境 conda activate your_env_name,然后执行pip install -r requirements.txt;

  • step4,按照Getting Started执行即可,推荐使用PyCharm

Getting Started

python get_data.py  --name ssq  # 执行获取双色球训练数据

如果出现解析错误,应该看看网页 http://datachart.500.com/ssq/history/newinc/history.php 是否可以正常访问 若要大乐透,替换参数 --name dlt 即可

python run_train_model.py --name ssq  # 执行训练双色球模型

开始模型训练,先训练红球模型,再训练蓝球模型,模型参数和超参数在 config.py 文件中自行配置 具体训练时间消耗与模型参数和超参数相关。

python run_predict.py  --name ssq # 执行双色球模型预测

预测结果会打印在控制台

Update

  • 新增模型预测评估,可以自行调整训练集和测试集比例,建议训练集采样比例高于0.5

  • 修复大乐透蓝球号码预测超出取值范围问题,修复训练传参数导致数据维度不匹配问题

  • 有盆友反馈想要个大乐透的预测玩法,加入对大乐透的数据爬取,模型训练,模型预测等功能,通过传入执行参数 --name dlt即可。

  • 为了降低本项目的使用门槛,废弃docker模式和微服务,按照Getting Started执行脚本,即可获取预测结果。

  • 非常开心有更多的同志们关注项目,并且提出了很多宝贵的问题,但是由于工作较忙,没有给大家比较完善的解答,再次说句抱歉, 大部分问题都是安装依赖问题,我更新了requirements.txt中相关库版本,应该可以解决。

  • 之前有issue反应,因为不同红球模型预测会有重复号码出现,所以将红球序列整体作为一个序列模型看待,推翻之前红球之间相互独立设定, 因为序列模型预测要引入crf层,相关API必须在 tf.compat.v1.disable_eager_execution()下,故整个模型采用 1.x 构建和训练模式, 在 2.x 的tensorflow中 tf.compat.v1.XXX 保留了 1.x 的接口方式。

predict_lottery_ticket's People

Contributors

zepen 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

predict_lottery_ticket's Issues

load model报错

我尝试在train里面增加load model的代码,以期能中断后重新开始train。
代码类似run_api中的load model。
但是在sess.run()后会报错:
Fetch argument <tf.Operation 'Adam' type=NoOp> cannot be interpreted as a Tensor.

Tensorflow写的不多,求解惑

运行完成没有数据

我运行成功 没有值 不知道怎么回事 谢谢!
[INFO] 模型加载成功!

Serving Flask app "predict_api" (lazy loading)
Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
Debug mode: off
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
运行完这结果 怎么办 呜呜

运行报错

手动创建了data文件夹拉取历史数据,运行train_model的时候报这个错:

ValueError: A target array with shape (2616, 24) was passed for an output of shape (None, 0) while using as loss categorical_crossentropy. This loss expects targets to have the same shape as the output.

m1 chip not support ?

System information

OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacBook Air Apple M1 chip, macOS Monterey version 12.2
Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: N/A
TensorFlow installed from (source or binary): binary
TensorFlow version: 2.1.0
Python version: 3.6.12
Installed using virtualenv? pip? conda?: pip3

Describe the problem
when i run

python train_model.py
[1]    59236 illegal hardware instruction  python train_model.py

预测结果

你好 请问你这代码为什么不显示预测结果?还是你这代码只是显示往期已经开奖的号码?

神经网络真能拟合吗?

看loss的趋势感觉一直就是在波动,没有明显下降趋势,而且红球们很多次预测出的结果都一样,感觉最终结果可能不如概率?

依赖版本问题

经过测试,0.10.0版本的tensorflow-addons并不支持2.6.1版本的tensorflow-cpu,并且,2.5以上版本的tensorflow-cpu貌似不支持CRF,2.4版本的tensorflow-cpu不能很好的进行序列化,因此,个人推荐以下依赖版本:
tensorflow-cpu==2.3.*
tensorflow-addons==0.13.*
requests
keras
beautifulsoup4
pandas
numpy
lxml
loguru
grpcio
protobuf

但是,这样还是会有save时序列化warning的小问题,测试后发觉不影响使用

报错

大佬能写个详细点的教程
报错报的我脑瓜子嗡嗡的。。。
1

Dockerfile 编译不通过

=> ERROR [5/5] RUN pip install --no-cache-dir -r requirements.txt 3.3s

[5/5] RUN pip install --no-cache-dir -r requirements.txt:
#9 0.765 Collecting Flask==1.1.2
#9 1.189 Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
#9 1.765 ERROR: Could not find a version that satisfies the requirement tensorflow-cpu==2.6.1 (from versions: none)
#9 1.765 ERROR: No matching distribution found for tensorflow-cpu==2.6.1


executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1

数据不显示

我使用的虚拟机,所有插件版本都是request.txt里的,除了numpy 是1.19.5以外(如果使用request里的1.17.2,在训练的时候会出现:Python Fatal Error: GC Object already Tracked 的报错。). Python 是3.6.13.

取数据和训练都顺利完成(会提示没有nvidia驱动,不过也能完成训练)。

运行了run_api.py后,打开 127.0.0.1:5000 是 “Welcome to use!”,如果打开127.0.0.1:5000/predict_api/ ,则报错:"GET /predict_api/ HTTP/1.1" 404 -; 如果打开127.0.0.1:5000/predict_api (没有"/"), 则报错:
ERROR in app: Exception on /predict_api [GET]
Traceback (most recent call last):
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/xxxxxx/.local/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "run_api.py", line 53, in get_predict_result
diff_number = windows_size - 1
SystemError: unknown opcode
"GET /predict_api HTTP/1.1" 500 -

是我哪里没配置对吗?请抽空解答下,谢谢。

有没有不需要gpu的能在虚拟机里跑起来的版本?

`2022-01-05 19:00:23.411489: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2022-01-05 19:00:23.411637: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2022-01-05 19:00:23.411655: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
2022-01-05 19:00:29.139770: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2022-01-05 19:00:29.139906: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)
2022-01-05 19:00:29.139977: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (leon): /proc/driver/nvidia/version does not exist
2022-01-05 19:00:29.159883: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2022-01-05 19:00:29.247429: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2904000000 Hz
2022-01-05 19:00:29.266784: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x6ec1b00 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2022-01-05 19:00:29.266858: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
[INFO] 已加载红球模型!
[INFO] 已加载蓝球模型!

  • Serving Flask app "run_api" (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on all addresses.
    WARNING: This is a development server. Do not use it in a production deployment.
  • Running on http://192.168.6.200:5000/ (Press CTRL+C to quit)`

运行报错 get_train_data.py

发生异常: TypeError
'NoneType' object is not subscriptable
File "D:\下载\predict_Lottery_ticket-master\get_train_data.py", line 19, in get_current_number
current_num = soup.find("div", class_="wrap_datachart").find("input", id="end")["value"]
File "D:\下载\predict_Lottery_ticket-master\get_train_data.py", line 64, in
print("[INFO] 最新一期期号:{}".format(get_current_number()))

有参数的相关解释文档吗,谢谢了

模型相关参数

windows_size = 3
batch_size = 1
sequence_len = 6
red_n_class = 33
red_epochs = 1
red_embedding_size = 32
red_hidden_size = 32
red_layer_size = 1
blue_n_class = 16
blue_epochs = 1
blue_embedding_size = 32
blue_hidden_size = 32
blue_layer_size = 1

模型训练参数

red_learning_rate = 0.001
red_beta1 = 0.9
red_beta2 = 0.999
red_epsilon = 1e-08
blue_learning_rate = 0.001
blue_beta1 = 0.9
blue_beta2 = 0.999
blue_epsilon = 1e-08

predict_api的正确使用

大佬,就我训练结束后运行predict_api文件后一直卡在下图这里。我之前没有使用过微服务,希望大佬给点指导,感谢。

1

on jetson nano lstm error

WARNING:tensorflow:Layer lstm_2 will not use cuDNN kernel since it doesn't meet the cuDNN kernel criteria. It will use generic GPU kernel as fallback when running on GPU

依赖包问题

Flask==1.1.2
tensorflow-cpu==2.6.2
tensorflow-addons==0.14.0
requests==2.22.0
beautifulsoup4==4.9.3
pandas==1.0.0
numpy==1.19.5
lxml==4.6.5
gunicorn==20.1.0
gevent==1.4.0
loguru==0.6.0
grpcio==1.46.0
protobuf==3.18.1

更新后按照这个配置能正常启动,麻烦楼主帮忙确认一下,是否有问题;
另外想请教下大神,当前的算法是基于之前出现的次数最少算出来的么。。模型有没有优化算法的想法或者计划。。

能否指教一下模型参数怎么设置?

如题,使用默认参数,经过多次训练后发现红球,蓝球每次都会在固定的数字附近徘徊,每次训练后的结果趋于固定的结果,请指教模型参数怎样调试

项目报错

问题1: bs4 只能安装 0.0.1版本

Could not fetch URL https://pypi.org/simple/bs4/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/bs4/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:841)'),)) - skipping
ERROR: Could not find a version that satisfies the requirement bs4==4.9.3
ERROR: No matching distribution found for bs4==4.9.3
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:841)'),)) - skipping

问题2: 执行 python get_train_data.py

Traceback (most recent call last):
  File "get_train_data.py", line 64, in <module>
    print("[INFO] 最新一期期号:{}".format(get_current_number()))
  File "get_train_data.py", line 18, in get_current_number
    soup = BeautifulSoup(r.text, "lxml")
  File "E:\software\Python\lib\site-packages\bs4\__init__.py", line 246, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

问题3: 执行python run_api.py

Traceback (most recent call last):
  File "run_api.py", line 15, in <module>
    model_red_1 = load_model('model/lstm_model_红球号码_1.h5')
  File "E:\software\Python\lib\site-packages\tensorflow_core\python\keras\saving\save.py", line 149, in load_model
    loader_impl.parse_saved_model(filepath)
  File "E:\software\Python\lib\site-packages\tensorflow_core\python\saved_model\loader_impl.py", line 83, in parse_saved_model
    constants.SAVED_MODEL_FILENAME_PB))
OSError: SavedModel file does not exist at: model/lstm_model_红球号码_1.h5/{saved_model.pbtxt|saved_model.pb}

预测概率

能否输出各个数字的概率数据,而不是单纯给一组号码。
比如红球 33 个,每个的概率在本期是多少,蓝球也是如此。
谢谢!

有一个小问题想请教

我train的时候总是报WARNING:tensorflow:Layer lstm_1 will not use cuDNN kernels since it doesn't meet the criteria. It will use a generic GPU kernel as fallback when running on GPU.结果就是,貌似大部分计算都去了cpu,gpu非常空闲。
我尝试按照stackoverflow的方法修改,但是没有成功,只能请教作者解决方法

一些建议

其实彩票本身是一件随机事件,不过既然有数值,就有概率。我们可以排除一些概率最小的数字,建立一个排除列表,主要是红球,比如6个连续号码,这种概率是极低的。另外统计一下过往的连续号码最大位数和次数作为备选号码。还有一种就是重复开奖号码,如果重复开奖率极低,可以纳入排除列表。把范围缩小,概率自然就大一点。

预测过拟合

预测过拟合,随机性不够。
后续的预测数字,重复数字太高了

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.