def testDraw3(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam','AwayTeam','FTHG','FTAG']] results = results.rename(columns={'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals'}) results_data = pd.concat([results[['HomeTeam','AwayTeam','HomeGoals']].assign(home=1).rename(columns={'HomeTeam':'team', 'AwayTeam':'opponent','HomeGoals':'goals'}), results[['AwayTeam','HomeTeam','AwayGoals']].assign(home=0).rename(columns={'AwayTeam':'team', 'HomeTeam':'opponent','AwayGoals':'goals'})]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() sou_mid = simulate_match(poisson_model, "Southampton", "Middlesbrough") sou_hull = simulate_match(poisson_model, "Southampton", "Hull") sou_burn = simulate_match(poisson_model, "Southampton", "Burnley") awaywin = (np.sum(np.triu(sou_mid, -1)) + np.sum(np.triu(sou_hull, -1)) + np.sum(np.triu(sou_burn, -1)))/3 draw = (np.sum(np.diag(sou_mid)) + np.sum(np.diag(sou_hull)) + np.sum(np.diag(sou_burn)))/3 self.assertGreater(awaywin, draw)
def testManCLiv(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam', 'AwayTeam', 'FTHG', 'FTAG']] results = results.rename(columns={ 'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals' }) results_data = pd.concat([ results[['HomeTeam', 'AwayTeam', 'HomeGoals']].assign(home=1).rename(columns={ 'HomeTeam': 'team', 'AwayTeam': 'opponent', 'HomeGoals': 'goals' }), results[['AwayTeam', 'HomeTeam', 'AwayGoals']].assign(home=0).rename(columns={ 'AwayTeam': 'team', 'HomeTeam': 'opponent', 'AwayGoals': 'goals' }) ]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() manc_lfc = simulate_match(poisson_model, "Man City", "Liverpool") homewin = np.sum(np.tril(manc_lfc, -1)) awaywin = np.sum(np.triu(manc_lfc, 1)) self.assertGreater(homewin, awaywin)
def testSpursArs(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam', 'AwayTeam', 'FTHG', 'FTAG']] results = results.rename(columns={ 'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals' }) results_data = pd.concat([ results[['HomeTeam', 'AwayTeam', 'HomeGoals']].assign(home=1).rename(columns={ 'HomeTeam': 'team', 'AwayTeam': 'opponent', 'HomeGoals': 'goals' }), results[['AwayTeam', 'HomeTeam', 'AwayGoals']].assign(home=0).rename(columns={ 'AwayTeam': 'team', 'HomeTeam': 'opponent', 'AwayGoals': 'goals' }) ]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() spurs_ars = simulate_match(poisson_model, "Tottenham", "Arsenal") homewin = np.sum(np.tril(spurs_ars, -1)) awaywin = np.sum(np.triu(spurs_ars, 1)) self.assertGreater(homewin, awaywin)
def testEverChel(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam', 'AwayTeam', 'FTHG', 'FTAG']] results = results.rename(columns={ 'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals' }) results_data = pd.concat([ results[['HomeTeam', 'AwayTeam', 'HomeGoals']].assign(home=1).rename(columns={ 'HomeTeam': 'team', 'AwayTeam': 'opponent', 'HomeGoals': 'goals' }), results[['AwayTeam', 'HomeTeam', 'AwayGoals']].assign(home=0).rename(columns={ 'AwayTeam': 'team', 'HomeTeam': 'opponent', 'AwayGoals': 'goals' }) ]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() eve_chel = simulate_match(poisson_model, "Everton", "Chelsea") homewin = np.sum(np.tril(eve_chel, -1)) awaywin = np.sum(np.triu(eve_chel, 1)) self.assertLess(homewin, awaywin)
def testHomeWin3(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam','AwayTeam','FTHG','FTAG']] results = results.rename(columns={'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals'}) results_data = pd.concat([results[['HomeTeam','AwayTeam','HomeGoals']].assign(home=1).rename(columns={'HomeTeam':'team', 'AwayTeam':'opponent','HomeGoals':'goals'}), results[['AwayTeam','HomeTeam','AwayGoals']].assign(home=0).rename(columns={'AwayTeam':'team', 'HomeTeam':'opponent','AwayGoals':'goals'})]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() mid_lec = simulate_match(poisson_model, "Middlesbrough", "Leicester") hull_lec = simulate_match(poisson_model, "Hull", "Leicester") burn_lec = simulate_match(poisson_model, "Burnley", "Leicester") homewin = (np.sum(np.tril(mid_lec, -1)) + np.sum(np.tril(hull_lec, -1)) + np.sum(np.tril(burn_lec, -1)))/3 awaywin = (np.sum(np.triu(mid_lec, 1)) + np.sum(np.triu(hull_lec, 1)) + np.sum(np.triu(burn_lec, 1)))/3 self.assertLess(homewin, awaywin)
def testAwayLoss2(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam','AwayTeam','FTHG','FTAG']] results = results.rename(columns={'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals'}) results_data = pd.concat([results[['HomeTeam','AwayTeam','HomeGoals']].assign(home=1).rename(columns={'HomeTeam':'team', 'AwayTeam':'opponent','HomeGoals':'goals'}), results[['AwayTeam','HomeTeam','AwayGoals']].assign(home=0).rename(columns={'AwayTeam':'team', 'HomeTeam':'opponent','AwayGoals':'goals'})]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() lec_mid = simulate_match(poisson_model, "Leicester", "Middlesbrough") lec_hull = simulate_match(poisson_model, "Leicester", "Hull") lec_burn = simulate_match(poisson_model, "Leicester", "Burnley") homewin = (np.sum(np.tril(lec_mid, -1)) + np.sum(np.tril(lec_hull, -1)) + np.sum(np.tril(lec_burn, -1)))/3 awaywin = (np.sum(np.triu(lec_mid, 1)) + np.sum(np.triu(lec_hull, 1)) + np.sum(np.triu(lec_burn, 1)))/3 self.assertGreater(homewin, awaywin)
def test3(self): results = pd.read_csv("../Data/results.csv") results = results[['HomeTeam', 'AwayTeam', 'FTHG', 'FTAG']] results = results.rename(columns={ 'FTHG': 'HomeGoals', 'FTAG': 'AwayGoals' }) results_data = pd.concat([ results[['HomeTeam', 'AwayTeam', 'HomeGoals']].assign(home=1).rename(columns={ 'HomeTeam': 'team', 'AwayTeam': 'opponent', 'HomeGoals': 'goals' }), results[['AwayTeam', 'HomeTeam', 'AwayGoals']].assign(home=0).rename(columns={ 'AwayTeam': 'team', 'HomeTeam': 'opponent', 'AwayGoals': 'goals' }) ]) poisson_model = smf.glm(formula="goals ~ home + team + opponent", data=results_data, family=sm.families.Poisson()).fit() lfc_lei = simulate_match(poisson_model, "Liverpool", "Leicester") homewin = np.sum(np.tril(lfc_lei, -1)) homeloss = np.sum(np.triu(lfc_lei, 1)) homedraw = np.sum(np.diag(lfc_lei)) total = np.ceil(homeloss + homewin + homedraw) self.assertNotEqual(0.5, total)