This Dash application makes it possible to determine the expected goal of a shot according to several features.
Distance and angle of shot obviously have a very important impact. David Sumpter makes this clear on Friends of Tracking.
It seemed interesting to introduce new variables to see their impact. Indeed, it seems that a shot close and in the axis of the goal is easy to convert into a goal. However, the presence of one or more opponents in the shooting angle or the body part used has an impact on the expected goal.
The features used in the model are :
- Shooting angle
- Shooting distance
- Under Pressure : The player is under pressure during the shot
- One Touch : The player shoots directly into the ball
- Open Goal : it does not mean that there are no players in the shooting angle, but the player who shoots has an almost empty goal in front of him, or an empty goal, and that he can score very easily
- Technique used to shoot (Normal, Lob, Volley, etc...)
- Body Part used to shoot (Foot, Head, Other)
- Type : Shot from open play, a penalty kick or a free kick
- Number of players in the shooting angle of both teams
The model built is based on XGBoost.
Feature Impact is displayed thanks to the Shap package.
Data is provided by Statsbomb. They correspond to the matches played by Lionel Messi with FC Barcelona between seasons 2004/2005 and 2018/2019.
The comparison of both calibration curves and ROC AUC (Statsbomb Xg and model Xg) on the test dataset proves our model has a good quality.
One of the next steps is to test this model on other datasets.
import pandas
import numpy
import math
import seaborn
import matplotlib
import shap
import sklearn
import xgboost
import json
import pickle
import os
import dash
import dash_core_components
import dash_html_components
import dash_table
import plotly
import matplotlib
import shap
import pandas
import numpy
import json
import pickle
In dockerImage/app
python app.py
Then copy paste http://127.0.0.1:8050/ in a browser.
https://dash.plotly.com/deployment
Take the same folder as dockerImage and replace Dockerfile by Procfile (/heroku_procfile/Procfile) to deploy the app with Heroku.
1- Install Docker. https://docs.docker.com/get-docker/
2- Modify some lines of code in app.py. The goal is to have access to our app from outside the container.
app.run_server(host='0.0.0.0', port=8050, debug=True)
3- Build a docker image from the directory dockerImage.
docker build -t <image_name> .
4- Check the image is created.
docker images
5- Check that everything is working properly. The app is accessible at http://0.0.0.0:8050 .
docker run <image_name>
6- Then, deploy your app with a cloud service.