Women’s Soccer Expected Goals — Data Extraction — Part-Two: Extracting Key Pass Features

Wes Swager
5 min readSep 9, 2021

--

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 using the statsbombpy package to extract shot event key pass features from StatsBomb.

Background

Continued from part-one, explaining the process of extracting shot event data:

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

Wikipedia

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 Part-One

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

Extract Key Pass Features

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.

shot_key_pass_id is a feature for shot events which identifies specific pass events (indicating the event id feature value), as passes which lead directly to the shot (potential assist, if the shot were to score).

Create dataframes for pass events in each season of the target competitions

passes_df_37_42 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2018/2019', gender = 'female', split = True)['passes']passes_df_37_4 = sb.competition_events(country = 'England', division = "FA Women's Super League", season = '2019/2020', gender = 'female', split = True)['passes']passes_df_49_3 = sb.competition_events(country = 'United States of America', division = 'NWSL', season = '2018', gender = 'female', split = True)['passes']

Concatenate pass events dataframes into combined dataframe

passes_df = pd.concat([passes_df_37_42, passes_df_37_4, passes_df_49_3], ignore_index = True)passes_df.head()
print("Total Women's Club Competition Pass Events:", len(passes_df))Total Women's Club Competition Pass Events: 209122print('Total Pass Features:', passes_df.shape[1])Total Pass Features: 45

Create a key_pass_events list from shot_key_pass_id values for shot events

key_pass_events = list(shots_df[‘shot_key_pass_id’])

Search pass events for key passes

passes_to_shots_df = passes_df[passes_df['id'].isin(key_pass_events)]print("Pass Events Identified as 'shot_key_pass_id' for Shot Events:", len(passes_to_shots_df))Pass Events Identified as 'shot_key_pass_id' for Shot Events: 4164

Concatenate pass data from passes_df for passes identified as shot event key passes with shots_df

passes_df2 = passes_df.rename(columns = {'id': 'shot_key_pass_id'})extracted_data = pd.merge(shots_df, passes_df2, on = ['shot_key_pass_id'], how = 'left')

Results

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 continues the series for the data science workflow creating a women’s club soccer expected goals (xG) classification model, explaining the process of exploring other related events and their features.

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.

--

--