from turtle import pd import numpy as np df = pd.read_csv('voice.csv')
def linearRegression(homeTeam, awayTeam): import pandas as pd from sklearn.tree import DecisionTreeRegressor from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error from math import sqrt try: if ('Man United' in homeTeam): dataset = 'dataset/ManUHome.csv' elif ('Fulham' in homeTeam): dataset = 'dataset/FulhamHome.csv' elif ('Newcastle' in homeTeam): dataset = 'dataset/NewcastleHome.csv' elif ('Man City' in homeTeam): dataset = 'dataset/ManCHome.csv' elif ('Wolves' in homeTeam): dataset = 'dataset/WolvesHome.csv' elif ('Liverpool' in homeTeam): dataset = 'dataset/LiverpoolHome.csv' elif ('Southampton' in homeTeam): dataset = 'dataset/SouthamptonHome.csv' elif ('Arsenal' in homeTeam): dataset = 'dataset/ArsenalHome.csv' elif ('Burnley' in homeTeam): dataset = 'dataset/BurnleyHome.csv' elif ('Everton' in homeTeam): dataset = 'dataset/EvertonHome.csv' elif ('Leicester' in homeTeam): dataset = 'dataset/LeicesterHome.csv' elif ('Tottenham' in homeTeam): dataset = 'dataset/TottenhamHome.csv' elif ('West Ham' in homeTeam): dataset = 'dataset/WestHamHome.csv' elif ('Chelsea' in homeTeam): dataset = 'dataset/ChelseaHome.csv' elif ('Brighton' in homeTeam): dataset = 'dataset/BrightonHome.csv' elif ('Crystal Palace' in homeTeam): dataset = 'dataset/CrystalPalaceHome.csv' elif ('West Brom' in homeTeam): dataset = 'dataset/WestBromHome.csv' elif ('Sheffield United' in homeTeam): dataset = 'dataset/SheffieldUnitedHome.csv' elif ('Leeds' in homeTeam): dataset = 'dataset/LeedsHome.csv' elif ('Aston Villa' in homeTeam): dataset = 'dataset/AstonVillaHome.csv' ##Read Data from the Database into pandas df = pd.read_csv(dataset, sep=',', header=0) ##Declare the Columns You Want to Use as Features features = ['HTHG', 'HS', 'HST'] ##Specify the Prediction Target target = ['FTHG'] ##Clean Data df = df.dropna() ##Extract Features and Target ('Full time home goals') Values into Separate Dataframes X = df[features] y = df[target] ##Typical row from features print(X.iloc[2]) ##Linear Regression: Fit a model to the training set X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.50, train_size=0.50, random_state=324) regressor = LinearRegression() regressor.fit(X_train, y_train) ##Perform Prediction using Linear Regression Model y_prediction = regressor.predict(X_test) print(y_prediction) # sg.Print('Prediction for Home Team...', do_not_reroute_stdout=False) ##What is the mean of the expected target value in test set ? # print(y_test.describe()) ##Evaluate Linear Regression Accuracy using Root Mean Square Error RMSE = sqrt(mean_squared_error(y_true=y_test, y_pred=y_prediction)) # formatted_Home_RMSE = "{:.2f}".format(RMSE) formatted_Home_RMSE = round(RMSE) # print("\nPredicted amount of goals using Linear Regression for {0}\nin their next game against {2} is: {1}".format(homeTeam, formatted_Home_RMSE,awayTeam)) # print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_prediction)) # print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_prediction)) # print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_prediction))) ##Decision Tree Regressor - Fit a new regression model to the training set regressor = DecisionTreeRegressor(max_depth=20) regressor.fit(X_train, y_train) ##Perform Prediction using Decision Tree Regressor y_prediction = regressor.predict(X_test) y_prediction ##Evaluate Decision Tree Regression Accuracy using Root Mean Square Error RMSE2 = sqrt(mean_squared_error(y_true=y_test, y_pred=y_prediction)) # formatted_Home_RMSE2 = "{:.2f}".format(RMSE2) formatted_Home_RMSE2 = round(RMSE2) # print("\nPredicted amount of goals using Decision Tree Regression for {0}\nin their next game against {2} is: {1}".format(homeTeam, formatted_Home_RMSE2,awayTeam)) except: sg.Popup("No dataset available") try: if ('Man United' in awayTeam): dataset = 'dataset/ManUAway.csv' elif ('Fulham' in awayTeam): dataset = 'dataset/FulhamAway.csv' elif ('Newcastle' in awayTeam): dataset = 'dataset/NewcastleAway.csv' elif ('Man City' in awayTeam): dataset = 'dataset/ManCAway.csv' elif ('Wolves' in awayTeam): dataset = 'dataset/WolvesAway.csv' elif ('Liverpool' in awayTeam): dataset = 'dataset/LiverpoolAway.csv' elif ('Southampton' in awayTeam): dataset = 'dataset/SouthamptonAway.csv' elif ('Arsenal' in awayTeam): dataset = 'dataset/ArsenalAway.csv' elif ('Burnley' in awayTeam): dataset = 'dataset/BurnleyAway.csv' elif ('Everton' in awayTeam): dataset = 'dataset/EvertonAway.csv' elif ('Leicester' in awayTeam): dataset = 'dataset/LeicesterAway.csv' elif ('Tottenham' in awayTeam): dataset = 'dataset/TottenhamAway.csv' elif ('West Ham' in awayTeam): dataset = 'dataset/WestHamAway.csv' elif ('Chelsea' in awayTeam): dataset = 'dataset/ChelseaAway.csv' elif ('Brighton' in awayTeam): dataset = 'dataset/BrightonAway.csv' elif ('Crystal Palace' in awayTeam): dataset = 'dataset/CrystalPalaceAway.csv' elif ('West Brom' in awayTeam): dataset = 'dataset/WestBromAway.csv' elif ('Sheffield United' in awayTeam): dataset = 'dataset/SheffieldUnitedAway.csv' elif ('Leeds' in awayTeam): dataset = 'dataset/LeedsAway.csv' elif ('Aston Villa' in awayTeam): dataset = 'dataset/AstonVillaAway.csv' ##Read Data from the Database into pandas df = pd.read_csv(dataset, sep=',', header=0) ##Declare the Columns You Want to Use as Features features = ['HTAG', 'AS', 'AST'] ##Specify the Prediction Target target = ['FTAG'] ##Clean Data df = df.dropna() ##Extract Features and Target ('Full time away goals') Values into Separate Dataframes X = df[features] y = df[target] ##Typical row from features # print(X.iloc[2]) ##Linear Regression: Fit a model to the training set X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.75, train_size=0.25, random_state=324) regressor = LinearRegression() regressor.fit(X_train, y_train) ##Perform Prediction using Linear Regression Model y_prediction = regressor.predict(X_test) # sg.Print('\nPrediction for Away Team...', do_not_reroute_stdout=False) ##What is the mean of the expected target value in test set ? # print(y_test.describe()) ##Evaluate Linear Regression Accuracy using Root Mean Square Error RMSE = sqrt(mean_squared_error(y_true=y_test, y_pred=y_prediction)) # formatted_Away_RMSE = "{:.2f}".format(RMSE) formatted_Away_RMSE = round(RMSE) # print("\nPredicted amount of goals using Linear Regression for {0}\nin their next game against {2} is: {1}".format(awayTeam, formatted_Away_RMSE,homeTeam)) ##Decision Tree Regressor - Fit a new regression model to the training set regressor = DecisionTreeRegressor(max_depth=20) regressor.fit(X_train, y_train) ##Perform Prediction using Decision Tree Regressor y_prediction = regressor.predict(X_test) y_prediction ##Evaluate Decision Tree Regression Accuracy using Root Mean Square Error RMSE2 = sqrt(mean_squared_error(y_true=y_test, y_pred=y_prediction)) # formatted_Away_RMSE2 = "{:.2f}".format(RMSE2) formatted_Away_RMSE2 = round(RMSE2) # print("\nPredicted amount of goals using Decision Tree Regression for {0}\nin their next game against {2} is: {1}".format(awayTeam, formatted_Away_RMSE2,homeTeam)) except: sg.Popup("No dataset available") # formatted_Home_RMSE = round(formatted_Home_RMSE) # formatted_Away_RMSE = round(formatted_Away_RMSE) sg.Print("Match Predictions utilizing Machine Learning Algorithms", do_not_reroute_stdout=False) print("-------------------------------------------") print( "Predicted Match Score using Linear Regression\n {0} : {1} - {2} : {3}" .format(homeTeam[0], formatted_Home_RMSE, awayTeam[0], formatted_Away_RMSE)) print("-------------------------------------------") print( "Predicted Match Score using Decision Tree Regression\n {0} : {1} - {2} : {3}" .format(homeTeam[0], formatted_Home_RMSE2, awayTeam[0], formatted_Away_RMSE2)) # api(homeTeam, awayTeam, formatted_Home_RMSE2, formatted_Away_RMSE2) predictions = { 'homeTeam': homeTeam[0], 'awayTeam': awayTeam[0], 'homeTeamScore': formatted_Home_RMSE2, 'awayTeamScore': formatted_Away_RMSE2, } import json with open('json/predictions.json', 'w') as f: json.dump(predictions, f) from dynamoDB import dataWriter call(["python", "dynamoDB/dataWriter.py"])
from turtle import pd import pandas as pd from sklearn.neighbors import KNeighborsClassifier from sklearn.model_selection import train_test_split from sklearn import metrics PavoDataset = pd.read_csv('dataset.csv') print(PavoDataset.head(6)) print(PavoDataset.describe()) location = PavoDataset['location3'][:] print(location.head(6)) X = PavoDataset.drop(['location3', 'location1', 'location2'], axis=1) X_train, X_test, y_train, y_test = train_test_split(X, location, test_size=0.10) knn = KNeighborsClassifier(n_neighbors=3) #Train the model using the training sets knn.fit(X_train, y_train) P = [[207.4, 182.2, 189.4, 193.0, 193.6]] asa = knn.predict(P) print("2) Using K Neighbors Classifier Prediction is " + str(knn.predict(P))) #some_dict={35: [177.2, 178.0, 183.6, 177.2, 182.6], 89: [188.8, 185.8, 181.0, 190.0, 193.0], 92: [196.0, 196.0, 190.6, 191.2, 194.8], 267: [184.0, 177.2, 173.5, 174.6, 182.2]} some_dict = { 35: [177.8, 180.0, 182.2, 174.6, 182.8],
def logisticRegression(homeTeam, awayTeam): import pandas as pd import numpy as np from sklearn import preprocessing import matplotlib.pyplot as plt plt.rc("font", size=14) from sklearn.linear_model import LogisticRegression from sklearn.model_selection import train_test_split import seaborn as sns try: if ('Man United' in homeTeam): dataset = 'dataset/ManUHome.csv' elif ('Fulham' in homeTeam): dataset = 'dataset/FulhamHome.csv' elif ('Newcastle' in homeTeam): dataset = 'dataset/NewcastleHome.csv' elif ('Man City' in homeTeam): dataset = 'dataset/ManCHome.csv' elif ('Wolves' in homeTeam): dataset = 'dataset/WolvesHome.csv' elif ('Liverpool' in homeTeam): dataset = 'dataset/LiverpoolHome.csv' elif ('Southampton' in homeTeam): dataset = 'dataset/SouthamptonHome.csv' elif ('Arsenal' in homeTeam): dataset = 'dataset/ArsenalHome.csv' elif ('Burnley' in homeTeam): dataset = 'dataset/BurnleyHome.csv' elif ('Everton' in homeTeam): dataset = 'dataset/EvertonHome.csv' elif ('Leicester' in homeTeam): dataset = 'dataset/LeicesterHome.csv' elif ('Tottenham' in homeTeam): dataset = 'dataset/TottenhamHome.csv' elif ('West Ham' in homeTeam): dataset = 'dataset/WestHamHome.csv' elif ('Chelsea' in homeTeam): dataset = 'dataset/ChelseaHome.csv' elif ('Brighton' in homeTeam): dataset = 'dataset/BrightonHome.csv' elif ('Crystal Palace' in homeTeam): dataset = 'dataset/CrystalPalaceHome.csv' elif ('West Brom' in homeTeam): dataset = 'dataset/WestBromHome.csv' elif ('Sheffield United' in homeTeam): dataset = 'dataset/SheffieldUnitedHome.csv' elif ('Leeds' in homeTeam): dataset = 'dataset/LeedsHome.csv' elif ('Aston Villa' in homeTeam): dataset = 'dataset/AstonVillaHome.csv' ##Read Data from the Database into pandas df = pd.read_csv(dataset, sep=',', header=0) ##Declare the Columns You Want to Use as Features features = ['HTHG', 'HS', 'HST'] ##Specify the Prediction Target target = ['FTHG'] ##Clean Data df = df.dropna() ##Extract Features and Target ('Full time home goals') Values into Separate Dataframes X = df[features] y = df[target] ##Typical row from features print(X.iloc[2]) ##Logistic Regression: Fit a model to the training set X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.50, train_size=0.50, random_state=324) from sklearn.linear_model import LogisticRegression from sklearn import metrics logreg = LogisticRegression() logreg.fit(X_train, y_train) ##Perform Prediction using Logistic Regression Model y_prediction = logreg.predict(X_test) print(y_prediction) sg.Print('Prediction for Home Team...', do_not_reroute_stdout=False) print('Accuracy of logistic regression classifier on test set: {:.2f}'. format(logreg.score(X_test, y_test))) from sklearn.metrics import confusion_matrix confusion_matrix = confusion_matrix(y_test, y_prediction) print(confusion_matrix) except: sg.Popup("No dataset available")
def statistics(homeTeam, awayTeam): import pandas as pd import matplotlib.pyplot as plt plt.rc("font", size=14) try: if ('Man United' in homeTeam): dataset = 'dataset/ManUHome.csv' elif ('Fulham' in homeTeam): dataset = 'dataset/FulhamHome.csv' elif ('Newcastle' in homeTeam): dataset = 'dataset/NewcastleHome.csv' elif ('Man City' in homeTeam): dataset = 'dataset/ManCHome.csv' elif ('Wolves' in homeTeam): dataset = 'dataset/WolvesHome.csv' elif ('Liverpool' in homeTeam): dataset = 'dataset/LiverpoolHome.csv' elif ('Southampton' in homeTeam): dataset = 'dataset/SouthamptonHome.csv' elif ('Arsenal' in homeTeam): dataset = 'dataset/ArsenalHome.csv' elif ('Burnley' in homeTeam): dataset = 'dataset/BurnleyHome.csv' elif ('Everton' in homeTeam): dataset = 'dataset/EvertonHome.csv' elif ('Leicester' in homeTeam): dataset = 'dataset/LeicesterHome.csv' elif ('Tottenham' in homeTeam): dataset = 'dataset/TottenhamHome.csv' elif ('West Ham' in homeTeam): dataset = 'dataset/WestHamHome.csv' elif ('Chelsea' in homeTeam): dataset = 'dataset/ChelseaHome.csv' elif ('Brighton' in homeTeam): dataset = 'dataset/BrightonHome.csv' elif ('Crystal Palace' in homeTeam): dataset = 'dataset/CrystalPalaceHome.csv' elif ('West Brom' in homeTeam): dataset = 'dataset/WestBromHome.csv' elif ('Sheffield United' in homeTeam): dataset = 'dataset/SheffieldUnitedHome.csv' elif ('Leeds' in homeTeam): dataset = 'dataset/LeedsHome.csv' elif ('Aston Villa' in homeTeam): dataset = 'dataset/AstonVillaHome.csv' ##Read Data from the Database into pandas df = pd.read_csv(dataset, sep=',', header=0) ##Declare the Columns You Want to Use as Features features = ['HTHG', 'HS', 'HST'] ##Specify the Prediction Target target = ['FTHG'] ##Clean Data df = df.dropna() # sns.countplot(x='FTHG', data=data, palette='hls') # plt.show() # plt.savefig('count_plot') # data.groupby('FTHG').mean() # data.groupby('HS').mean() # data.groupby('HST').mean() pd.crosstab(df.FTHG, df.HS).plot(kind='bar') plt.title('{} home goals vs. shots'.format(homeTeam)) plt.xlabel('Goals') plt.ylabel('Shots') plt.savefig('img/goals_vs_shots_home') plt.show(block=True) # data.FTHG.hist() # plt.title('Histogram of Home Goals') # plt.xlabel('Goals') # plt.ylabel('Frequency') # plt.savefig('hist_goals') except: sg.Popup("No dataset available")
def predicting(homeTeam, awayTeam): import pandas as pd try: if ('Man United' in homeTeam): dataset = 'dataset/ManUHome.csv' elif ('Fulham' in homeTeam): dataset = 'dataset/FulhamHome.csv' elif ('Fulham' in awayTeam): dataset = 'dataset/FulhamAway.csv' elif ('Man United' in awayTeam): dataset = 'dataset/ManUAway.csv' if ('Man United' in homeTeam): dataset = 'dataset/ManUHome.csv' elif ('Fulham' in homeTeam): dataset = 'dataset/FulhamHome.csv' elif ('Newcastle' in homeTeam): dataset = 'dataset/NewcastleHome.csv' elif ('Man City' in homeTeam): dataset = 'dataset/ManCHome.csv' elif ('Wolves' in homeTeam): dataset = 'dataset/WolvesHome.csv' elif ('Liverpool' in homeTeam): dataset = 'dataset/LiverpoolHome.csv' elif ('Southampton' in homeTeam): dataset = 'dataset/SouthamptonHome.csv' elif ('Arsenal' in homeTeam): dataset = 'dataset/ArsenalHome.csv' elif ('Burnley' in homeTeam): dataset = 'dataset/BurnleyHome.csv' elif ('Everton' in homeTeam): dataset = 'dataset/EvertonHome.csv' elif ('Leicester' in homeTeam): dataset = 'dataset/LeicesterHome.csv' elif ('Tottenham' in homeTeam): dataset = 'dataset/TottenhamHome.csv' elif ('West Ham' in homeTeam): dataset = 'dataset/WestHamHome.csv' elif ('Chelsea' in homeTeam): dataset = 'dataset/ChelseaHome.csv' elif ('Brighton' in homeTeam): dataset = 'dataset/BrightonHome.csv' elif ('Crystal Palace' in homeTeam): dataset = 'dataset/CrystalPalaceHome.csv' elif ('West Brom' in homeTeam): dataset = 'dataset/WestBromHome.csv' elif ('Sheffield United' in homeTeam): dataset = 'dataset/SheffieldUnitedHome.csv' elif ('Leeds' in homeTeam): dataset = 'dataset/LeedsHome.csv' elif ('Aston Villa' in homeTeam): dataset = 'dataset/AstonVillaHome.csv' df1 = pd.read_csv(dataset, usecols=[ 'HomeTeam', 'AwayTeam', 'FTHG', 'FTAG', 'FTR', 'HTR', 'HS', 'AS', 'HST', 'AST', 'B365H', 'B365D', 'B365A' ]) df1.head() stdoutOrigin = sys.stdout sys.stdout = open("logs/log.txt", "w") from statsmodels.stats import proportion confHome = proportion.proportion_confint((df1['FTR'] == 'H').sum(), df1['FTR'].count(), alpha=0.05, method='wilson') confAway = proportion.proportion_confint((df1['FTR'] == 'A').sum(), df1['FTR'].count(), alpha=0.05, method='wilson') confDraw = proportion.proportion_confint((df1['FTR'] == 'D').sum(), df1['FTR'].count(), alpha=0.05, method='wilson') print( 'The chance of home team to win with %95 confidence interval falls in :{}' .format(confHome)) print( '--------------------------------------------------------------------------------' ) print( 'The chance of away team to win with %95 confidence interval falls in :{}' .format(confAway)) print( '--------------------------------------------------------------------------------' ) print('The chance of a draw with %95 confidence interval falls in :{}'. format(confDraw)) sys.stdout.close() sys.stdout = stdoutOrigin textPrinting('logs/log.txt') import matplotlib.pyplot as plt plt.figure(figsize=(6, 8)) plt.pie(df1['FTR'].value_counts(), labels=['Home Win', 'Home Loss', 'Draw'], autopct='%1.1f%%', shadow=True, startangle=0) plt.axis('equal') plt.title('Win Percentage', size=18) plt.show() sg.Popup("Complete") except: sg.Popup("No Matches")
with open(path, 'r') as file: allData = [] data = np.loadtxt(file, delimiter=delimiter) allData.append(data) allData = np.asarray(allData) return allData popt, pcov = curve_fit(gaus, x1, y1, p0=[1, mean, sigma]) a, mu, sigma = popt delta_a, delta_mu, delta_sigma = np.sqrt(np.diag(pcov)) # R^2 residuals = y1 - gaus(x1, *popt) ss_res = np.sum(residuals**2) ss_tot = np.sum((y1 - np.mean(y1))**2) r_squared = 1 - (ss_res / ss_tot) def gaus(x, a, x0, sigma): return a * np.exp(-(x - x0)**2 / (2 * sigma**2)) fit_param = [] ## Fig1 df1 = pd.read_csv('gaussien.csv', sep=";", header=1) x1 = df1.to_numpy().T[0].astype(float) y1 = df1.to_numpy().T[1].astype(float) x1_fit = np.linspace(x1[0], x1[-1], 1000) plt.plot(x1_fit, gaus(x1_fit, *popt), linewidth=0.5, alpha=0.75, color='C0')
import datetime from datetime import time from turtle import pd import pyautogui import subprocess subprocess.Popen("/Applications/OBS.app") position = pyautogui.locateOnScreen("buttons\\recording_button.png") # Move the cursor to the position of the button pyautogui.moveTo(position) # Perform click operation pyautogui.click() time.sleep(2) df = pd.read_csv('timetable.csv') while True: time = datetime.now().strftime("%H:%M") if time not in df.Time.values: position = pyautogui.locateOnScreen("button\\stoprecording_button.png") pyautogui.moveTo(position) break