Applying Weighting to the Goals Models#

[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]:
date datetime season competition div 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 2019-08-09 2019-08-09 20:00:00 2019-2020 ENG Premier League E0 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 2019-08-10 2019-08-10 15:00:00 2019-2020 ENG Premier League E0 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 2019-08-10 2019-08-10 15:00:00 2019-2020 ENG Premier League E0 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 2019-08-10 2019-08-10 15:00:00 2019-2020 ENG Premier League E0 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 2019-08-10 2019-08-10 17:30:00 2019-2020 ENG Premier League E0 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

Create the Weights#

[4]:
xi = 0.001
weights = pb.models.dixon_coles_weights(df["date"], xi)

Train the model#

[5]:
clf = pb.models.DixonColesGoalModel(
    df["goals_home"], df["goals_away"], df["team_home"], df["team_away"], weights
)
clf.fit()

The model’s parameters#

[6]:
clf
[6]:
Module: Penaltyblog

Model: Dixon and Coles

Number of parameters: 42
Log Likelihood: -879.671
AIC: 1843.343

Team                 Attack               Defence
------------------------------------------------------------
Arsenal              1.145                -0.96
Aston Villa          0.821                -0.642
Bournemouth          0.824                -0.649
Brighton             0.773                -0.836
Burnley              0.869                -0.941
Chelsea              1.348                -0.812
Crystal Palace       0.531                -0.912
Everton              0.898                -0.813
Leicester            1.283                -1.055
Liverpool            1.537                -1.264
Man City             1.727                -1.255
Man United           1.31                 -1.242
Newcastle            0.781                -0.768
Norwich              0.32                 -0.527
Sheffield United     0.756                -1.158
Southampton          1.069                -0.761
Tottenham            1.218                -0.972
Watford              0.733                -0.666
West Ham             1.026                -0.708
Wolves               1.031                -1.148
------------------------------------------------------------
Home Advantage: 0.239
Rho: -0.078
[7]:
clf.get_params()
[7]:
{'attack_Arsenal': np.float64(1.144949905929318),
 'attack_Aston Villa': np.float64(0.8211833050535601),
 'attack_Bournemouth': np.float64(0.8238000396326658),
 'attack_Brighton': np.float64(0.7730705244669612),
 'attack_Burnley': np.float64(0.8689343441725552),
 'attack_Chelsea': np.float64(1.3475855486891566),
 'attack_Crystal Palace': np.float64(0.5309831147050881),
 'attack_Everton': np.float64(0.898409705429681),
 'attack_Leicester': np.float64(1.282663505849936),
 'attack_Liverpool': np.float64(1.5372296425830276),
 'attack_Man City': np.float64(1.7267149046878532),
 'attack_Man United': np.float64(1.310318077147705),
 'attack_Newcastle': np.float64(0.7810821985130814),
 'attack_Norwich': np.float64(0.32031537569664587),
 'attack_Sheffield United': np.float64(0.756397077539036),
 'attack_Southampton': np.float64(1.068666804409662),
 'attack_Tottenham': np.float64(1.2184558429326078),
 'attack_Watford': np.float64(0.7325661771016169),
 'attack_West Ham': np.float64(1.0260467035815914),
 'attack_Wolves': np.float64(1.0306272018767515),
 'defence_Arsenal': np.float64(-0.9597520519607475),
 'defence_Aston Villa': np.float64(-0.6424612731039607),
 'defence_Bournemouth': np.float64(-0.6485814937773848),
 'defence_Brighton': np.float64(-0.8360247260429235),
 'defence_Burnley': np.float64(-0.9412626602561426),
 'defence_Chelsea': np.float64(-0.8121173879097644),
 'defence_Crystal Palace': np.float64(-0.911934038315484),
 'defence_Everton': np.float64(-0.8128562445182332),
 'defence_Leicester': np.float64(-1.0548116769925087),
 'defence_Liverpool': np.float64(-1.2639681889819574),
 'defence_Man City': np.float64(-1.2550748290155953),
 'defence_Man United': np.float64(-1.2420940177658861),
 'defence_Newcastle': np.float64(-0.7679483380308282),
 'defence_Norwich': np.float64(-0.5269116672528777),
 'defence_Sheffield United': np.float64(-1.1579048379110184),
 'defence_Southampton': np.float64(-0.7609806462356308),
 'defence_Tottenham': np.float64(-0.9715679787843047),
 'defence_Watford': np.float64(-0.6656257049737819),
 'defence_West Ham': np.float64(-0.7077751518777993),
 'defence_Wolves': np.float64(-1.148290961379967),
 'home_advantage': np.float64(0.23856467457373232),
 'rho': np.float64(-0.07846937040455315)}

Predict Match Outcomes#

[8]:
probs = clf.predict("Liverpool", "Wolves")
probs
[8]:
Module: Penaltyblog

Class: FootballProbabilityGrid

Home Goal Expectation: [1.8729287]
Away Goal Expectation: [0.79188351]

Home Win: 0.6215177796020613
Draw: 0.23427193067485133
Away Win: 0.14421028809547223

1x2 Probabilities#

[9]:
probs.home_draw_away
[9]:
[np.float64(0.6215177796020613),
 np.float64(0.23427193067485133),
 np.float64(0.14421028809547223)]
[10]:
probs.home_win
[10]:
np.float64(0.6215177796020613)
[11]:
probs.draw
[11]:
np.float64(0.23427193067485133)
[12]:
probs.away_win
[12]:
np.float64(0.14421028809547223)

Probablity of Total Goals >1.5#

[13]:
probs.total_goals("over", 1.5)
[13]:
np.float64(0.7529851084800863)

Probability of Asian Handicap 1.5#

[14]:
probs.asian_handicap("home", 1.5)
[14]:
np.float64(0.37547110035717224)

Probability of both teams scoring#

[15]:
probs.both_teams_to_score
[15]:
np.float64(0.4710502787522432)