This repository contains Python scripts for exploring lottery number prediction using a Recurrent Neural Network (RNN) with Long Short-Term Memory (LSTM) layers, built with TensorFlow/Keras.
Disclaimer: Lottery outcomes are inherently random and statistically independent events. While these scripts demonstrate machine learning techniques for pattern recognition, they do not guarantee accurate predictions or winning lottery numbers. The purpose is educational and for exploring statistical properties of lottery data.
To make it simple, it's like flipping the coin, knowing the previous one will not help in the new one.
TensorFlow-Lottery-Prediction/
├── ArchivioSuperAl1801_con7.csv # Example historical lottery data (replace with your own)
├── createModel.py # Script for training the LSTM model
├── predict.py # Script for making predictions using a trained model
└── README.md # This file
-
Clone the repository:
git clone <repository_url> cd TensorFlow-Lottery-Prediction
-
Install dependencies: It's recommended to use a virtual environment.
python -m venv venv source venv/bin/activate # On Windows: `venv\Scripts\activate` pip install numpy pandas scikit-learn tensorflow keras joblib
This script trains an LSTM model to predict various statistical patterns in lottery numbers. It supports different prediction types:
raw_numbers
: Predicts the raw scaled lottery numbers.sum
: Predicts the sum of the lottery numbers.counts
: Predicts the counts of even, odd, low, and high numbers.
Input: A CSV file containing historical lottery draw data.
Output: A trained Keras model (.h5
file), an input data scaler (.joblib
file), and a target-specific scaler (.joblib
file).
Example Commands:
Train for counts
prediction:
python createModel.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type counts \
--model_output lottery_model_counts.h5 \
--input_scaler_output scaler_input.joblib \
--target_scaler_output scaler_counts.joblib
Train for sum
prediction:
python createModel.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type sum \
--model_output lottery_model_sum.h5 \
--input_scaler_output scaler_input.joblib \
--target_scaler_output scaler_sum.joblib
Train for raw_numbers
prediction:
python createModel.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type raw_numbers \
--model_output lottery_model_raw.h5 \
--input_scaler_output scaler_input.joblib \
--target_scaler_output scaler_raw.joblib
Arguments:
--csv_file
(required): Path to the input CSV file containing lottery data. (Default:ArchivioSuperAl1801_con7.csv
)--prediction_type
(required): Type of prediction to train for:raw_numbers
,sum
, orcounts
.--model_output
: Path to save the trained Keras model. (Default:lottery_model_<prediction_type>.h5
)--input_scaler_output
: Path to save the fittedStandardScaler
object for input data. (Default:scaler_input.joblib
)--target_scaler_output
: Path to save the fittedStandardScaler
object for the target data. (Default:scaler_<prediction_type>.joblib
)
This script uses a pre-trained model and scalers to make predictions based on the latest historical data. It also supports different prediction types, which must match the type the model was trained on.
Input: A trained Keras model (.h5
file), an input data scaler (.joblib
file), a target-specific scaler (.joblib
file), and the latest historical lottery data CSV.
Output: Predicted values based on the chosen prediction type.
Example Commands:
Predict counts
:
python predict.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type counts \
--model_path lottery_model_counts.h5 \
--input_scaler_path scaler_input.joblib \
--target_scaler_path scaler_counts.joblib
Predict sum
:
python predict.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type sum \
--model_path lottery_model_sum.h5 \
--input_scaler_path scaler_input.joblib \
--target_scaler_path scaler_sum.joblib
Predict raw_numbers
:
python predict.py --csv_file ArchivioSuperAl1801_con7.csv \
--prediction_type raw_numbers \
--model_path lottery_model_raw.h5 \
--input_scaler_path scaler_input.joblib \
--target_scaler_path scaler_raw.joblib
Example of output :
Input for prediction (last 7 draws):
A B C D E F G
7089 37 42 49 53 57 65 62
7090 26 45 58 65 70 82 27
7091 16 46 61 71 75 85 64
7092 1 33 40 61 64 73 15
7093 5 15 20 32 65 75 12
7094 1 31 40 62 64 74 81
7095 16 24 25 43 64 78 54
1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 302ms/step
--- Predicted Sum ---
Raw predicted sum (float): 324.01
Rounded to nearest integer: 324
Rounded up (ceil): 325
Rounded down (floor): 324
zsh: command not found: --model_path
zsh: command not found: --target_scaler_path
Arguments:
--csv_file
(required): Path to the input CSV file containing lottery data. (Default:ArchivioSuperAl1801_con7.csv
)--prediction_type
(required): Type of prediction to perform:raw_numbers
,sum
, orcounts
.--model_path
: Path to the trained Keras model file. (Default:lottery_model_<prediction_type>.h5
)--input_scaler_path
: Path to the fittedStandardScaler
object for input data. (Default:scaler_input.joblib
)--target_scaler_path
: Path to the fittedStandardScaler
object for the target data. (Default:scaler_<prediction_type>.joblib
)
- Docstrings: Both Python files include comprehensive docstrings explaining their purpose, functions, arguments, and usage.
- Comments: Inline comments are used to clarify complex logic and important sections.
- Argparse: Command-line arguments are used for flexible execution and easy configuration.
- Error Handling: Basic error handling for file operations is included.
- Modularity: Functions are used to encapsulate core logic.
- More Data Preprocessing: Explore different ways to preprocess the lottery numbers (e.g., one-hot encoding, binning).
- Hyperparameter Tuning: Experiment with different LSTM layers, units, dropout rates, learning rates, and batch sizes.
- Different Prediction Targets: Predict other statistical properties (e.g., sum of first three numbers, range of numbers).
- Visualization: Add scripts to visualize training progress and prediction results.
- Unit Testing: Implement unit tests for data preparation and model components.