Florida Lottery Powerball Winning Number Generator and Predictor
Tags: machinelearning, scikitlearn, python, springboot
Published: 2021-04-20 04:57:05

`An effort to make sense out of random winning numbers/draws in last 10 years`

--- 

>
Odds of winning the Powerball lottery jackpot is 1:222M. Despite of known understanding that the drawn numbers are completely random, this project is an effort to identify pattern in jackpot winning draws based on the history of Powerball draws.


>
This project uses neural network algorithm to classify the draw to be winning or losing. Random number generator tool generates n random draws which are then passed through the Multilayer Perceptron Classifier to find out the winning numbers. Classifier accuracy has been measured up-to 97.4% (which also means there is 2.6% of tolerance). It should be noted that the numbers generated by this project may not be the next jackpot, but it certainly increases the chances of winning the jackpot. Generated numbers may not be the next jackpot, but it will eventually be in future draws.

>
This project is mere an experiment. Owner of this project is not responsible of any monetary or emotional loss. Also, owner is not willing to grab any piece of monetary gain done by the generated numbers. User should understand that the generated numbers are mere suggestions, and not the jackpot number as yet.


---
---

# Project Details
## Dataset source
[Powerball History Draws](http://www.flalottery.com/exptkt/pb.pdf)

## Machine Learning

- Library : scikit-learn
- Scripting : Python
- File operations : Pandas
- Classifiers :
  - MLPClassifier
  - SGDClassifier

## Random Number Generator

- Application name : winners-analysis
- Type : Spring Boot with RestController to trigger number generation and writing to csv

# Technical Details

## The dataset

> - Powerball winning number data from Florida Lottery website
> - Mega Millions winning number data from Florida Lottery website
> - Pdf data transformed into csv
> - Training data set prepared by mixing winning and random losing numbers

## Number Generator

`The Spring project : winners-analysis`

It generates n draws containing numbers which are randomly generated.

The ranges of numbers are :

```
1 : 1–69
2 : 1–69
3 : 1–69
4 : 1–69
5 : 1–69
PB : 1–26
```

> These generated numbers are written to csv file which can be used as test data for the machine learning model.

## Draws generator APIs

> - `GET /draw/generate/{n}` : Generate n draws and write to csv file which can be supplied to machine learning model for prediction
> - `GET /draw/repeatedRandom/{n}` : Generate m draws (∀ m <= n) and write to csv file that can be supplied to machine learning model for prediction. The generated draws are the repeated combination of the draws when random numbers generated n times. Theory says these numbers may have higher chances to be the jackpot number. Also, it returns ~1300 out of 1 million random generated draws, which are then passed through the model results in ~20 lucky numbers.

## Machine learning model

> Multi-layer Perceptron model with 100 hidden layers has been used to reach accuracy ~ 97%.

Below steps are used to perform machine learning:

1. Collect training data (csv) generated by winners-analysis Spring project.
2. Read csv using pandas library and split train and test data with 20% test data.

```python
Initialize MLPClassifier from sklearn.neural-network
from sklearn.neural_network import MLPClassifier
clf = MLPClassifier(alpha=1, max_iter=5000)
```

3. Fit training data into the classifier
4. Predict output for the test data and calculate the accuracy

```python
from sklearn.metrics import accuracy_score
score = accuracy_score(y_test, y_pred)
```

---

# Activity

Pick the latest draw winning and pass through the model for prediction. There is 97% chances the result is going to be winning.

---

# TODO

- Automate end to end flow
- Deploy and make it available for public
- Real-time retraining the model after each Powerball draw to improve the accuracy over the period

---

✌️