text_plain_output_1.png image_output_1.png
from datetime import datetime, timedelta, date

import matplotlib.pyplot as plt

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
from datetime import datetime, timedelta, date
from statistics import mean
import copy
from keras.models import Sequential
from keras.layers import LSTM, Dropout, Dense, Activation
from sklearn.preprocessing import StandardScaler
sns.set(rc={'figure.figsize': (11, 8)})
pd.set_option('display.max_rows', 20)
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 1000)
plt.rcParams['axes.grid'] = False
import os
paths = []
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        paths.append(os.path.join(dirname, filename))

lotteryPath = paths[0]

lottery = pd.read_csv(lotteryPath, encoding='latin-1')
lottery

all_balls = {}
for i in range(1, 7):
    ball_ser = lottery['Ball ' + str(i)].value_counts()
    for key in ball_ser.keys():
        all_balls[key] = all_balls.get(key, 0) + ball_ser[key]
ball_ser = lottery['Extra Ball'].value_counts()
for key in ball_ser.keys():
    all_balls[key] = all_balls.get(key, 0) + ball_ser[key]
all_balls = pd.Series(all_balls)
plt.xticks(rotation=0)

# Visualize the distributions of each ball
f, axes = plt.subplots(7, 1)
f.tight_layout() 
for i in range(1,7):
    ball_dist = lottery['Ball ' +str(i)].value_counts().sort_index()
    axes[i-1].set_title('Distribution of ball '+str(i))
    plt.xticks(rotation=90)
    sns.barplot(x=ball_dist.keys(), y=ball_dist.values, ax=axes[i-1], palette="PuBuGn_d")

ball_dist = lottery['Extra Ball'].value_counts().sort_index()
axes[6].set_title('Distribution of extra ball')
plt.xticks(rotation=90)
sns.barplot(x=ball_dist.keys(), y=ball_dist.values, ax=axes[6], palette="PuBuGn_d")

# Correlation matrix
def plotCorrelationMatrix(df, graphWidth):
    #filename = df.dataframeName
    df = df.dropna('columns') # drop columns with NaN
    del df['Draw Number']
    df = df[[col for col in df if df[col].nunique() > 1]] # keep columns where there are more than 1 unique values
    if df.shape[1] < 2:
        print(f'No correlation plots shown: The number of non-NaN or constant columns ({df.shape[1]}) is less than 2')
        return
    corr = df.corr('pearson')
    plt.figure(num=None, figsize=(graphWidth, graphWidth), dpi=80, facecolor='w', edgecolor='k')
    corrMat = plt.matshow(corr, fignum = 1,cmap = "BuGn")
    plt.xticks(range(len(corr.columns)), corr.columns, rotation=0)
    plt.yticks(range(len(corr.columns)), corr.columns)
    plt.gca().xaxis.tick_bottom()
    plt.colorbar(corrMat)
   
    plt.title(f'Correlation Matrix', fontsize=15)
    plt.show()
plotCorrelationMatrix(lottery, 8)

allMonthsData = []
class MonthData:
    def __init__(self, date, ballsDict):
        self.date = date
        self.ballsDict = ballsDict

def generateStatsForDraws(draws, drawDate):
    if draws.empty == False:
        currentBalls = {}
        del draws['Date']
        del draws['Draw Number']
        del draws['Jackpot']
        balls_list = draws.values.T.tolist()
        balls_flat_list = [item for sublist in balls_list for item in sublist]
        for i in range(1, 43):
            currentBalls[i] = balls_flat_list.count(i)
        data = MonthData(drawDate, currentBalls)
        allMonthsData.append(data)
def plotBallsInMonths(index):
    all_balls = pd.Series(allMonthsData[index].ballsDict)
    plt.xticks(rotation=0)

plotBallsInMonths(50)