Expected Goals Model - Interactive Visualisation (Part 1)
- Emmeran J

- Jun 3, 2024
- 2 min read
Expected Goals (xG) models have become more widespread over the past few seasons with most major broadcasters now displaying xG statistics of some sort (e.g. see Sky Sports match reports and xG timeline below). Even the video-game Fifa (or EA Sports FC now) give xG figures at the end of a game.

Sky Sports xG Timeline from Manchester United - Liverpool 2-2 match on 7th of April 2024
But as far as I can tell, there is little transparency about the models used. Often, only xG aggregated over a match (for a team) or a season (for a player) is given and it is surprisingly difficult to find xG figures for a single shot (there are some opta plots but the precise xG is not given). Furthermore, it is unclear what is taken into account to compute the xG (i.e. features used)? xG models can vary quite significantly, especially if tracking data is included to account for the positioning of defenders and goalkeeper and arguably not taking this into account can lead to pretty meaningless xG stats (think a shot from just inside the box when 1) a striker is 1v1 after a counter-attack VS 2) the box is crowded with a well-shaped defence).
As a fan, I think it would be interesting to be able to access exact xG figures and understand what features contributed to the xG being so high or low. Even more interesting would be to be able to play around with the features and see how the xG changes if the player had been a couple of metres closer or had taken the shot with their other foot. As far as I am aware, none of the above are publicly available (but please let me know if a company / broadcaster / club offers these functionalities). This gave me the idea to develop my own interactive xG visualisation, where the user can select a point anywhere on the pitch along with other features of the model and observe the output of the xG model.
This first iteration below is focused on getting the interactive visualisation working, not on an elaborate xG model. The xG model is taken from Soccermatics with a manual tweak for left and right footed shots (which in no way reflect reality - I just wanted there to be a difference in the xG output). Future posts will focus on more elaborate xG models as well as improving the visualisations and interactivity in terms of aesthetics and functionalities. In the meantime, here is the first version - you can select a point on the pitch where you want to consider a shot from, there is an option to choose between left and right foot and to overlay the heatmap of xG across the pitch if you do not want to select a specific point. Enjoy!
This interactive plot was created using the python library plotly (and dash) and it is hosted online through render.com. The code can be found on my github.
I am very much learning as I go so please let me know if you have comments / feedback / suggestions. Thanks for reading and look out for more posts in the future!
(note: there is something similar in a nice post at https://torvaney.github.io/projects/xG.html)

Comments