Rue Salvesen
[1]:
import sys
sys.path.append("../../")
import penaltyblog as pb
Get data from football-data.co.uk
[2]:
fb = pb.scrapers.FootballData("ENG Premier League", "2019-2020")
df = fb.get_fixtures()
df.head()
[2]:
competition | season | datetime | div | date | time | team_home | team_away | fthg | ftag | ... | b365_cahh | b365_caha | pcahh | pcaha | max_cahh | max_caha | avg_cahh | avg_caha | goals_home | goals_away | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||||
1565308800---liverpool---norwich | ENG Premier League | 2019-2020 | 2019-08-09 20:00:00 | E0 | 2019-08-09 | 20:00 | Liverpool | Norwich | 4 | 1 | ... | 1.91 | 1.99 | 1.94 | 1.98 | 1.99 | 2.07 | 1.90 | 1.99 | 4 | 1 |
1565395200---bournemouth---sheffield_united | ENG Premier League | 2019-2020 | 2019-08-10 15:00:00 | E0 | 2019-08-10 | 15:00 | Bournemouth | Sheffield United | 1 | 1 | ... | 1.95 | 1.95 | 1.98 | 1.95 | 2.00 | 1.96 | 1.96 | 1.92 | 1 | 1 |
1565395200---burnley---southampton | ENG Premier League | 2019-2020 | 2019-08-10 15:00:00 | E0 | 2019-08-10 | 15:00 | Burnley | Southampton | 3 | 0 | ... | 1.87 | 2.03 | 1.89 | 2.03 | 1.90 | 2.07 | 1.86 | 2.02 | 3 | 0 |
1565395200---crystal_palace---everton | ENG Premier League | 2019-2020 | 2019-08-10 15:00:00 | E0 | 2019-08-10 | 15:00 | Crystal Palace | Everton | 0 | 0 | ... | 1.82 | 2.08 | 1.97 | 1.96 | 2.03 | 2.08 | 1.96 | 1.93 | 0 | 0 |
1565395200---tottenham---aston_villa | ENG Premier League | 2019-2020 | 2019-08-10 17:30:00 | E0 | 2019-08-10 | 17:30 | Tottenham | Aston Villa | 3 | 1 | ... | 2.10 | 1.70 | 2.18 | 1.77 | 2.21 | 1.87 | 2.08 | 1.80 | 3 | 1 |
5 rows × 111 columns
Train the model
[3]:
clf = pb.models.RueSalvesenGoalModel(
df["goals_home"], df["goals_away"], df["team_home"], df["team_away"]
)
clf.fit()
The model’s parameters
[4]:
clf
[4]:
Module: Penaltyblog
Model: Rue Salvesen
Number of parameters: 43
Log Likelihood: -1022.249
AIC: 2130.497
Team Attack Defence
------------------------------------------------------------
Arsenal 1.112 -1.035
Aston Villa 0.804 -0.707
Bournemouth 0.762 -0.568
Brighton 0.744 -0.909
Burnley 0.871 -1.036
Chelsea 1.503 -0.539
Crystal Palace 0.474 -1.14
Everton 0.891 -0.742
Leicester 1.229 -1.077
Liverpool 1.586 -1.277
Man City 1.652 -1.065
Man United 1.418 -1.29
Newcastle 0.778 -0.541
Norwich 0.275 -0.733
Sheffield United 0.763 -1.387
Southampton 1.149 -0.793
Tottenham 1.166 -0.944
Watford 0.721 -0.72
West Ham 0.99 -0.532
Wolves 1.114 -1.251
------------------------------------------------------------
Home Advantage: 0.241
Rho: -0.432
Gamma: -0.306
[5]:
clf.get_params()
[5]:
{'attack_Arsenal': 1.111931449095879,
'attack_Aston Villa': 0.8036584045882671,
'attack_Bournemouth': 0.7616274831177443,
'attack_Brighton': 0.7438029939011236,
'attack_Burnley': 0.8714749753346606,
'attack_Chelsea': 1.5031298228608796,
'attack_Crystal Palace': 0.473943204227092,
'attack_Everton': 0.8905730783721502,
'attack_Leicester': 1.2290703186815548,
'attack_Liverpool': 1.5856160570398277,
'attack_Man City': 1.6520840743943552,
'attack_Man United': 1.417691292532406,
'attack_Newcastle': 0.7783536013404229,
'attack_Norwich': 0.2750967380076478,
'attack_Sheffield United': 0.7634361220531481,
'attack_Southampton': 1.148616150311251,
'attack_Tottenham': 1.165938538146421,
'attack_Watford': 0.7205743721370401,
'attack_West Ham': 0.9898150953383186,
'attack_Wolves': 1.113566228512511,
'defence_Arsenal': -1.034889597180056,
'defence_Aston Villa': -0.7069292337686073,
'defence_Bournemouth': -0.5681822350334952,
'defence_Brighton': -0.9088289955476304,
'defence_Burnley': -1.035513131410702,
'defence_Chelsea': -0.5386051915163717,
'defence_Crystal Palace': -1.1399498461579118,
'defence_Everton': -0.7423896283707103,
'defence_Leicester': -1.0766704375173184,
'defence_Liverpool': -1.2772161070917725,
'defence_Man City': -1.065205892940396,
'defence_Man United': -1.2899010102737807,
'defence_Newcastle': -0.5410115575004688,
'defence_Norwich': -0.7332598945150457,
'defence_Sheffield United': -1.3868341605873409,
'defence_Southampton': -0.7934806614414996,
'defence_Tottenham': -0.9444089336826985,
'defence_Watford': -0.7199536018083285,
'defence_West Ham': -0.5319430115288346,
'defence_Wolves': -1.2514668089034262,
'home_advantage': 0.24101616914181714,
'rho': -0.43193928553416344,
'rue_salvesen': -0.3057690852799766}
Predict Match Outcomes
[6]:
probs = clf.predict("Liverpool", "Wolves")
probs
[6]:
Module: Penaltyblog
Class: FootballProbabilityGrid
Home Goal Expectation: 1.9029358346336849
Away Goal Expectation: 0.7930394339420297
Home Win: 0.5918369228555458
Draw: 0.30277883299657615
Away Win: 0.10538424213892131
1x2 Probabilities
[7]:
probs.home_draw_away
[7]:
[0.5918369228555458, 0.30277883299657615, 0.10538424213892131]
[8]:
probs.home_win
[8]:
0.5918369228555458
[9]:
probs.draw
[9]:
0.30277883299657615
[10]:
probs.away_win
[10]:
0.10538424213892131
Probablity of Total Goals >1.5
[11]:
probs.total_goals("over", 1.5)
[11]:
0.7945923403157933
Probability of Asian Handicap 1.5
[12]:
probs.asian_handicap("home", 1.5)
[12]:
0.3828536297404947
Probability of both teams scoring
[13]:
probs.both_teams_to_score
[13]:
0.5098629006377844