Women’s Soccer Expected Goals — Data Extraction — Part-Three: Exploring Related Events
Part-two of a series for the data science workflow creating a women’s club soccer expected goals (xG) classification model, explaining the process of exploring related events and their features.
Background
Continued from parts-one and two, explaining the processes of extracting shot event data and key pass features:
Introduction
Expected Goals (xG)
xG is used to indicate the quality of a shot.
xG, as a metric, measures the likelihood that a shot will result in a goal based on the characteristics of the shot and the play preceding the shot.
xG is measured on a scale between zero and one, with one representing a goal. For example, a shot with a 0.5 xG indicates a shot having a 50% chance of being a goal.
Classification Model
The metric of expected goals is calculated through the use of a classification model.
A classification model refers to a predictive modeling problem where a class label is predicted for a given example of input data.
For this project a supervised approach was used with the training data for the model including which shots were goals.
Data Extraction
Data extraction is the act or process of retrieving data out of…data sources for further data processing
The Data
The data for this project was extracted from StatsBomb’s Open Data.
StatsBomb are a United Kingdom based football (soccer) data analytics company. StatsBomb provide free access to a segment of their proprietary dataset via GitHub: StatsBomb Open Data
StatsBomb Open Data is organized in JSON files:
Matches
- Folders are organized by competition (league or tournament)
- Files within the folders are organized by season (year) ID
- Files contain nested dictionaries with descriptive data for each individual match
Events
- Files organized by match ID
- Files contain nested dictionaries with descriptive data for each event within each individual match
For the purposes of this project the relevant data targeted was, primarily, characteristics of shots and, secondarily, characteristics of the plays creating those shots, from women’s club soccer matches.
Note: Assessment of plays creating shots is subjective and based on domain knowledge specific to the sport of soccer
statsbombpy
The following processes of extracting data from the StatsBomb Open Data relies heavily on the use of statsbombpy.
statsbombpy is a Python package created by StatsBomb which streams StatsBomb data directly within python. The package allows access to StatsBomb Open Data for free or allows access to their API with use of log-in credentials.
Data Extraction
Import statsbombpy for extracting StatsBomb data
!pip install statsbombpy
from statsbombpy import sb
Review from Parts-One and Two
Previously, in Soccer Expected Goals — Data Extraction — Part-One: Extracting Shots Data, target women’s club competitions, competition ids, and season ids were identified and isolated from StatsBomb matches data.
matches_df.head()
print('Number of Seasons:', len(target_season_ids))Number of Women's Club Seasons: 3print('Total Women's Club Matches:', len(matches_df))Total Matches: 231
Then, shot event data was extracted from StatsBomb events data.
shots_df.head()
print("Total Women's Club Shot Events:", len(shots_df))Total Women's Club Competition Shot Events: 6114print('Total Shot Features:', shots_df.shape[1])Total Shot Features: 37
Next, in Soccer Expected Goals — Data Extraction — Part-Two: Extracting Key Pass Features, the features for pass events identified by the shot events’ shot_key_pass_id feature were extracted and concatenated with their shot events.
extracted_data.head()
print("Total Women's Club Shot Events:", len(extracted_data))Total Women's Club Competition Shot Events: 6114print('Updated Shot w/ Key Pass Features:', extracted_data.shape[1])Updated Shot w/ Key Pass Features: 81
Related Events
As mentioned previously, characteristics of the play creating a shot can be valuable toward the potential quality of the shot. For this reason, features of other event types related to shot events can be valuable and worth assessment.
related_events is a feature for shot events which identifies specific events other than shot or pass events (indicating the event id feature value), as events significantly connected with leading to the shot.
In exploring the types of events available in the StatsBomb data, dribble and carry events appear to be the event types most likely to provide valuable data toward describing the quality of the shot.
Note: Assessment of plays creating shots is subjective and based on domain knowledge specific to the sport of soccer
Create a list from related_events values for shot events
related_events = list(shots_df['related_events'])
Dribble Events
Create dataframes for dribble events in each season of the target competitions
dribbless_df_37_42 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2018/2019', gender = 'female', split = True)['dribbles']dribbles_df_37_4 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2019/2020', gender = 'female', split = True)['dribbles']dribbles_df_49_3 = sb.competition_events(country = 'United States of America', division = 'NWSL', season = '2018', gender = 'female', split = True)['dribbles']
Concatenate dribble event dataframes into a combined dataframe
dribbles_df = pd.concat([dribbles_df_37_42, dribbles_df_37_4, dribbles_df_49_3], ignore_index = True)dribbles_df.head()
print("Total Women's Club Competition Dribble Events:", len(dribbles_df))Total Women's Club Competition Dribble Events: 8187print('Total Dribble Features:', dribbles_df.shape[1])Total Dribble Features: 23
Search dribble events for related_events
dribbles_to_shots_df = dribbles_df[dribbles_df[‘id’].isin(related_events)]print(“Dribble Events Identified as ‘related_events’ for Shot Events:”, len(dribbles_to_shots_df))Dribble Events Identified as 'related_events' for Shot Events: 0
No related_events values for shot events match the id feature values of dribble events, therefore no additional data can be extracted or added.
Carry Events
Create dataframes for carry events in each season of the target competitions
carrys_df_37_42 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2018/2019', gender = 'female', split = True)['carrys']carrys_df_37_4 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2019/2020', gender = 'female', split = True)['carrys']carrys_df_49_3 = sb.competition_events(country = 'United States of America', division = 'NWSL', season = '2018', gender = 'female', split = True)['carrys']
Concatenate carry event dataframes into a combined dataframe
carrys_df = pd.concat([carrys_df_37_42, carrys_df_37_4, carrys_df_49_3], ignore_index = True)carrys_df.head()
print("Total Women's Club Competition Carry Events:", len(carrys_df))Total Women's Club Competition Carry Events: 168439print('Total Carry Features:', carrys_df.shape[1])Total Carry Features: 19
Search carry events for related_events
carrys_to_shots_df = carrys_df[carrys_df[‘id’].isin(related_events)]print(“Carry Events Identified as ‘related_events’ for Shot Events:”, len(carrys_to_shots_df))Carry Events Identified as 'related_events' for Shot Events: 0
No related_events values for shot events match the id feature values of carry events, therefore no additional data can be extracted or added.
Conclusion
In exploring related events and their features no additional features were found to be considered valuable toward the potential quality of the shot.
No related_events values for shot events match the id feature values of either dribble or carry events, therefore no additional data can be extracted or added.
Results
Note: No changes were made to extracted_data following the extraction of shot event data and key pass features as a result of assessing related events.
print("Total Women's Club Shot Events:", len(extracted_data))Total Women's Club Competition Shot Events: 6114print('Updated Shot w/ Key Pass Features:', extracted_data.shape[1])Updated Shot w/ Key Pass Features: 81
The additional extraction of key pass features increased the number of features for the 6,144 shot events from 37 to 81.
extracted_data.head()
Continued
Part-three completes data extraction portion for the data science workflow creating a women’s club soccer expected goals (xG) classification model.
Next the series will continue in the data cleaning portion, explaining the process of defining the target feature for modeling, goal.
More
If you liked this post, please give it an applause and follow me as I will be continuing with a series of posts for each process through the data science workflow of my Women’s Soccer Expected Goals Model:
Also, follow me on Twitter, where I post regularly about tactical observations for soccer:
I would love to read any feedback you might have in the comments.