This is an open-source learning project for AI lottery prediction, developed for educational purposes only. We accidentally discovered that AI models trained on lottery data showed surprisingly good prediction capabilities. However, we strongly emphasize that lottery prediction is for academic research only and should never be used for commercial purposes or investment decisions.
- Trained on all lottery data from 2009 onwards
- Predicts the next 14 days of China Sports Lottery Pick 3 (体彩排列3)
- Best model performance: 4 days with 1 correct number, 2 days with 2 correct numbers, and 1 day with all 3 correct numbers
- Another model consistently predicted 1 correct number for 8 consecutive days
- Uses Transformer model with custom evaluation functions
- Verified no future data leakage
AI prediction example showing prediction results visualization
- Lottery prediction is inherently uncertain and risky
- This project is for educational purposes only
- DO NOT use for any commercial activities
- DO NOT use for investment decisions
- The project developers are not responsible for any losses incurred
- Python 10
- TensorFlow 2.10
- SQL Server
- Transformer models
- CUDA (for GPU acceleration)
- GPU-equipped computer (required for model training and inference)
- SQL Server database
- Install SQL Server database
- Windows: Download from Microsoft SQL Server Official Download
- Linux/macOS: Use Docker to run SQL Server:
# Run SQL Server in Docker docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourPassword123" -p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server:2022-latest
- Or use SQL Server Express (Free): SQL Server Express Download
- Restore the database backup from
db/caipiaodb.bak
Command Line Restore (using sqlcmd):
# Restore database using command line
sqlcmd -S localhost -U sa -P YourPassword -Q "RESTORE DATABASE [caipiaodb] FROM DISK = 'db\caipiaodb.bak' WITH REPLACE"
# Alternative with Windows Authentication
sqlcmd -S localhost -E -Q "RESTORE DATABASE [caipiaodb] FROM DISK = 'db\caipiaodb.bak' WITH REPLACE"SQL Server Management Studio (SSMS) Restore:
-
Open SSMS and connect to your SQL Server instance
-
Right-click on "Databases" → "Restore Database"
-
Select "Device" as the source
-
Click "Add" and browse to
db/caipiaodb.bak -
Click "OK" to restore
-
Configure database connection string in
config.py
Installation Environment Overview: This project requires Python 3.10.11 + TensorFlow 2.10.1 for optimal compatibility. The installation process includes database setup (SQL Server), Python environment configuration, and TensorFlow installation. Windows users are recommended to use the pre-configured environment or install TensorFlow 2.10.1 specifically. Linux/macOS users have more flexible version options. GPU support is recommended for better training performance.
Quick Start Guide:
- Database: Install SQL Server and restore backup from
db/caipiaodb.bak - Python Environment: Use Python 3.10.11 for Windows, Python 3.10+ for Linux/macOS
- TensorFlow: Windows requires TensorFlow 2.10.1 specifically, Linux/macOS flexible
- Dependencies: Install all packages from
requirements.txt
For Windows Users (Recommended):
-
Install Python 3.10.11 (recommended version for this project)
-
IMPORTANT: Install TensorFlow 2.10.1 specifically (not other versions):
pip install tensorflow==2.10.1
- This version is optimized for Windows + Python 3.10.11
- Using other TensorFlow versions may cause compatibility issues
If pip installation cannot find the required version, you can manually install local TensorFlow:
- Download the local installation package from cloud storage:
- File:
tensorflow_gpu-2.10.1-cp310-cp310-win_amd64.whl - Link: https://pan.baidu.com/s/13PeTy7Tb-Sdc77awgzmQ2w?pwd=2qj4
- Extraction code: 2qj4
- File:
- Manual installation:
pip install tensorflow_gpu-2.10.1-cp310-cp310-win_amd64.whl
-
Install CUDA compatible with TensorFlow 2.10 (if using GPU)
- CUDA + cuDNN Installation Guide: TensorFlow GPU Support
- CUDA Toolkit 11.8 Download: CUDA 11.8
- cuDNN v8.6 Download: cuDNN Library
-
Install remaining dependencies from
requirements.txt
For Linux/macOS Users:
- Install Python 3.10+
- Install main dependencies (flexible versions):
# Create virtual environment python -m venv venv # Activate virtual environment # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate # Install main dependencies (versions can vary) pip install tensorflow numpy pandas scikit-learn matplotlib pymssql
Complete Installation (All Platforms):
# Install all dependencies
pip install -r requirements.txtKey Dependencies Version:
- TensorFlow 2.10.1 (Python 3.10.11 compatible)
- NumPy 1.24.2 (Scientific computing)
- Scikit-learn 1.2.2 (Machine learning)
- Pandas 1.5.3 (Data manipulation)
- Matplotlib 3.7.1 (Visualization)
- pymssql 2.2.7 (SQL Server connectivity)
-
Download the pre-configured environment from Baidu Netdisk:
- Link:
https://pan.baidu.com/s/1cCKQ2zNqeN0B-f16bEzNAw?pwd=9ezr - Extraction code: 9ezr
- Link:
-
Set up Windows System Environment Variables:
- Extract Python 3.10.11 to
C:\Python310 - Add to PATH environment variable:
C:\Python310 C:\Python310\Scripts C:\Python310\Lib\site-packages - Set AICuda environment paths:
C:\AICuda\bin - Verification: Open Command Prompt and run
python --versionto confirm Python 3.10.11 is accessible Note: The pre-configured tensorflow9 environment already includes all required dependencies, including TensorFlow.
- Extract Python 3.10.11 to
-
Activate TensorFlow 9 Virtual Environment:
# Navigate to project directory cd /path/to/your/project # Activate the pre-configured tensorflow9 environment E:\AI\tensorflow9\Scripts\activate
-
Run the main program:
python CaiAi3PNew.py
- Main program:
CaiAi3PNew.py - Run directly to start training or prediction
# Prediction model ID (when IsFix=False)
sup.dset.guid = "model_id_from_mainlist"
# True: Start training; False: Predictions
sup.dset.IsFix = True
# Model type (from AiModels.py GetModel method)
sup.dset.tfModelType = "model_name"
# For custom data training
sup.dset.LeftNum = 2 # Number of prefix columns (issue number, date, etc.)
sup.dset.OutNum = 3 # Number of output columns (actual results)- China Sports Lottery Pick 3 model path:
SaveModels/AiCaiData3PNew/FixModels - Model list:
SaveModels/AiCaiData3PNew/mainlist
Model performance statistics and template analysis
- Input data only needs to be 2D features - the program automatically processes it into time series input shape
- For China Sports Lottery Pick 3, the optimal historical review days is 30
- Recommended model:
l_cai_hierarchical_l2 - Prediction output shows the next period's data based on the current input period
- Prepare your lottery data in SQL Server
- Write SQL queries to get 2D feature data
- Configure
LeftNumandOutNumparameters according to your data structure - Run the training process
For questions or custom requirements:
- WeChat Customer Service:
https://work.weixin.qq.com/kfid/kfcd871154619f798d8
这是一个用于AI彩票预测的开源学习项目,仅用于教育目的。我们在测试模型时偶然发现,使用彩票数据训练的AI模型展现出了令人惊讶的预测能力。然而,我们强烈强调,彩票预测仅用于学术研究,绝不能用于商业目的或投资决策。
- 训练数据包含2009年以来的所有彩票数据
- 预测未来14天的体彩排列3结果
- 最佳模型表现:4天中1个数,2天中2个数,1天中3个数
- 另一个模型连续8天每天中1个数
- 使用Transformer模型和自定义评估函数
- 已验证未使用未来数据
- 彩票预测本质上具有不确定性和风险性
- 本项目仅用于教育目的
- 禁止用于任何商业活动
- 禁止用于投资决策
- 项目开发者对任何损失不承担责任
- Python 10
- TensorFlow 2.10
- SQL Server
- Transformer模型
- CUDA (GPU加速)
- 配备GPU的电脑 (模型训练和推理必需)
- SQL Server数据库
- 安装SQL Server数据库
- Windows: 下载地址:Microsoft SQL Server 官方下载
- Linux/macOS: 使用Docker运行SQL Server:
# 在Docker中运行SQL Server docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourPassword123" -p 1433:1433 --name sqlserver -d mcr.microsoft.com/mssql/server:2022-latest
- 或使用SQL Server Express(免费版):SQL Server Express 下载
- 还原
db/caipiaodb.bak中的数据库备份
数据库还原方法一:命令行还原(使用sqlcmd):
# 使用命令行还原数据库
sqlcmd -S localhost -U sa -P 你的密码 -Q "RESTORE DATABASE [caipiaodb] FROM DISK = 'db\caipiaodb.bak' WITH REPLACE"
# Windows身份验证方式
sqlcmd -S localhost -E -Q "RESTORE DATABASE [caipiaodb] FROM DISK = 'db\caipiaodb.bak' WITH REPLACE"数据库还原方法二:SQL Server Management Studio (SSMS) 还原:
-
打开SSMS并连接到SQL Server实例
-
右键点击"数据库" → "还原数据库"
-
选择"设备"作为源
-
点击"添加"并浏览到
db/caipiaodb.bak -
点击"确定"进行还原
-
在
config.py中配置数据库连接字符串
安装环境总结简介: 本项目需要Python 3.10.11 + TensorFlow 2.10.1以获得最佳兼容性。安装过程包括数据库设置(SQL Server)、Python环境配置和TensorFlow安装。Windows用户推荐使用预配置环境或专门安装TensorFlow 2.10.1版本。Linux/macOS用户有更灵活的版本选项。推荐使用GPU支持以获得更好的训练性能。
快速开始指南:
- 数据库:安装SQL Server并从
db/caipiaodb.bak恢复备份 - Python环境:Windows使用Python 3.10.11,Linux/macOS使用Python 3.10+
- TensorFlow:Windows需专门安装TensorFlow 2.10.1,Linux/macOS版本灵活
- 依赖项:从
requirements.txt安装所有包
Windows用户(推荐):
-
安装Python 3.10.11(项目推荐版本)
-
专门安装TensorFlow 2.10.1版本:
pip install tensorflow==2.10.1
如果pip安装未找到相关版本,可以手动安装本地TensorFlow:
- 从网盘下载本地安装包:
- 文件:
tensorflow_gpu-2.10.1-cp310-cp310-win_amd64.whl - 链接: https://pan.baidu.com/s/13PeTy7Tb-Sdc77awgzmQ2w?pwd=2qj4
- 提取码: 2qj4
- 文件:
- 手动安装:
pip install tensorflow_gpu-2.10.1-cp310-cp310-win_amd64.whl
- 从网盘下载本地安装包:
-
安装与TensorFlow 2.10兼容的CUDA(如果使用GPU)
- CUDA + cuDNN 安装教程: TensorFlow GPU支持
- CUDA Toolkit 11.8 下载: CUDA 11.8
- cuDNN v8.6 下载: cuDNN 库
-
从
requirements.txt安装其余依赖
Linux/macOS用户:
- 安装Python 3.10+
- 安装主要依赖库(版本灵活):
# 创建虚拟环境 python -m venv venv # 激活虚拟环境 # Windows系统: venv\Scripts\activate # macOS/Linux系统: source venv/bin/activate # 安装主要依赖(版本可灵活) pip install tensorflow numpy pandas scikit-learn matplotlib pymssql
完整安装(所有平台):
# 安装所有依赖
pip install -r requirements.txt关键依赖版本:
- TensorFlow 2.10.1 (Python 3.10.11兼容)
- NumPy 1.24.2 (科学计算)
- Scikit-learn 1.2.2 (机器学习)
- Pandas 1.5.3 (数据处理)
- Matplotlib 3.7.1 (数据可视化)
- pymssql 2.2.7 (SQL Server连接)
-
从百度网盘下载预配置环境:
- 链接:
https://pan.baidu.com/s/1cCKQ2zNqeN0B-f16bEzNAw?pwd=9ezr - 提取码: 9ezr
- 链接:
-
设置Windows系统环境变量:
- 将Python 3.10.11解压到
C:\Python310 - 添加到PATH环境变量:
C:\Python310 C:\Python310\Scripts C:\Python310\Lib\site-packages - 设置AICuda环境路径:
C:\AICuda\bin - 验证:打开命令提示符,运行
python --version确认Python 3.10.11可访问 注意:预配置的tensorflow9环境已经包含了所有必要的依赖包,包括TensorFlow,无需额外安装。
- 将Python 3.10.11解压到
-
激活TensorFlow 9虚拟环境:
# 导航到项目目录 cd /path/to/your/project # 激活预配置的tensorflow9环境 E:\AI\tensorflow9\Scripts\activate
-
运行主程序:
python CaiAi3PNew.py
- 主程序:
CaiAi3PNew.py - 直接运行开始训练或预测
# 预测模型ID(当IsFix=False时)
sup.dset.guid = "mainlist中的模型ID"
# True:开始训练;False:预测
sup.dset.IsFix = True
# 模型类型(来自AiModels.py的GetModel方法)
sup.dset.tfModelType = "模型名称"
# 自定义数据训练配置
sup.dset.LeftNum = 2 # 前置列数,即期号日期等标识字段
sup.dset.OutNum = 3 # 输出列数,即真实结果值- 体彩排列3模型路径:
SaveModels/AiCaiData3PNew/FixModels - 模型列表:
SaveModels/AiCaiData3PNew/mainlist
- 数据查询输入只需要二维特征,程序已自动处理成时间序列输入形状
- 体彩排列3最佳历史回顾天数为30
- 推荐模型:
l_cai_hierarchical_l2 - 预测输出显示的期号为当前输入数据期号预测的是下一期的数据
- 在SQL Server中准备你的彩票数据
- 编写SQL查询获取二维特征数据
- 根据你的数据结构配置
LeftNum和OutNum参数 - 运行训练过程
如有疑问或定制化需求:
- 微信客服:
https://work.weixin.qq.com/kfid/kfcd871154619f798d8
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
This license is chosen because:
- NonCommercial: Prohibits commercial use, aligning with our project's educational-only purpose
- Attribution: Requires proper credit to the original authors
- ShareAlike: Ensures any modifications are shared under the same non-commercial terms
- Strong protection: Prevents misuse for commercial or investment purposes while allowing open learning and modification
For the full license text, see the LICENSE file.
© 2025 Witplay AI Lottery Prediction Project Team