socceraction

repository·master·Indexed 21 days ago

https://github.com/ml-kuleuven/socceraction

A Python package for quantifying the impact of individual soccer player actions using event stream data. It converts proprietary data from providers like StatsBomb, Opta, Wyscout, Stats Perform, and WhoScored into unified SPADL and atomic-SPADL formats. The library implements possession value frameworks, including Expected Threat (xT), VAEP, and Atomic-VAEP, to assign values to on-the-ball actions.

Tokens
24.9K
Snippets
72
Records
117
Agent score
74%

What's inside socceraction

  1. What is socceraction and what are its core features?

    master

    socceraction is an open-source Python package designed to simplify soccer event stream data analysis. Its primary functions include:

    • VAEP Implementation: Provides an implementation of the VAEP (Valuing Actions by Expected Possession) possession value framework.
    • Data Loading: Includes API clients to load data from popular providers like StatsBomb, Wyscout, and Opta (Stats Perform).
    • Data Conversion: Converts proprietary data formats from various providers into a common action-based data format called SPADL (Soccer Player Action Description Language), which standardizes preprocessing for subsequent analysis.
  2. Overview of socceraction components

    master

    socceraction is a Python toolkit designed to quantify the value of individual soccer player actions using event stream data. The package provides four main functional areas:

    1. Data Ingestion: API clients to load event stream data from major providers: StatsBomb, Wyscout, and Opta.
    2. Data Standardization: Converters that transform proprietary provider formats into unified, expressive languages: SPADL and atomic-SPADL.
    3. Expected Threat (xT): An implementation of the xT possession value framework.
    4. VAEP & Atomic-VAEP: Implementations of the VAEP and Atomic-VAEP possession value frameworks.

    Note: If you are following external video tutorials (e.g., from the Friends of Tracking series), be aware they may be based on version 0.2.0. You may need to adapt the code for the current version of the library.

  3. Overview of socceraction features

    master

    Socceraction is a Python package designed to quantify the impact of individual soccer player actions using event stream data. It provides a pipeline to convert raw data into actionable player values.

    Key components include:

    • Data Loading: API clients to load event stream data from StatsBomb, Opta, Wyscout, Stats Perform, and WhoScored into unified Pandas DataFrames.
    • Data Conversion: Converters to transform proprietary provider formats into SPADL and atomic-SPADL (unified, expressive languages for on-the-ball player actions).
    • Possession Value Frameworks:
      • Expected Threat (xT): Implementation of the xT framework.
      • VAEP and Atomic-VAEP: Implementation of the VAEP and Atomic-VAEP frameworks for valuing actions.
  4. Load event data from different providers using socceraction.data

    master

    The socceraction.data module provides specialized submodules for loading and processing event data from major football data providers. Depending on your data source, you should use the corresponding module:

    • StatsBomb: Use for loading StatsBomb event data.
    • Opta: Use for loading Opta event data, including derived formats used by Stats Perform and WhoScored.
    • Wyscout: Use for loading Wyscout event data.
  5. What is Atomic-SPADL?

    master

    Atomic-SPADL is a variation of the SPADL format designed to treat every action as an independent, completed event. Unlike standard SPADL, which might treat a pass as a single action involving both an initiator and a receiver, Atomic-SPADL splits these into separate actions (e.g., a pass action for the giver and a receival action for the receiver).

    This distinction allows for more precise analysis of the contributions of individual players. For example, if a pass is not successful, Atomic-SPADL uses specific action types like interception or out to describe the outcome, rather than a single combined action.

  6. What is SPADL (Soccer Player Action Description Language)?

    master

    SPADL is a standardized representation of a soccer game as a sequence of on-the-ball actions. Each action is a tuple containing twelve specific attributes that describe the event, the participants, and the spatial context.

    Action Attributes

    AttributeDescription
    game_idThe ID of the game
    period_idThe ID of the game period
    secondsThe action's start time
    playerThe player who performed the action
    teamThe player's team
    start_xThe x location where the action started
    start_yThe y location where the action started
    end_xThe x location where the action ended
    end_yThe y location where the action ended
    action_typeThe type of action (e.g., pass, shot, dribble)
    resultThe result of the action (e.g., success, fail)
    bodypartThe player's body part used (e.g., foot, head)

    Coordinate System

    SPADL uses a standardized 105m x 68m coordinate system with the origin at the bottom left of the pitch. By default, it uses the "home team attacks to the right" convention. You can use socceraction.spadl.play_left_to_right to convert coordinates so that lower x-coordinates represent the team's own half.

  7. How VAEP works: Valuing Actions by Estimating Probabilities

    master

    VAEP (Valuing Actions by Estimating Probabilities) evaluates the impact of player actions by assessing how they change the probability of scoring or conceding a goal in the short-term future (typically the next 10 actions).

    An action's value is derived from two components:

    1. Offensive Value: The change in scoring probability ($\Delta P_{\text{score}}$) resulting from an action.
    2. Defensive Value: The change in conceding probability ($\Delta P_{\text{concede}}$) resulting from an action.

    The total VAEP value of an action is calculated as the difference between its offensive and defensive values:

    $V_{\text{VAEP}}(a_i) = \Delta P_{\text{score}}(a_{i}, t) - \Delta P_{\text{concede}}(a_{i}, t)$

  8. Understand the Socceraction data representation model

    master

    Socceraction uses a tabular action-oriented data format. This differs from commercial event-based formats in two key ways:

    1. Actions vs. Events: Socceraction focuses on actions (subsets of events that require a player to perform them, such as a pass) rather than all events (which might include non-player actions like the end of a game).
    2. Uniform Attributes: Unlike many event stream formats, Socceraction stores the same attributes for every action. This consistency allows the data to be stored in a table, making it compatible with automatic analysis tools.

    Socceraction implements two specific versions of this format:

    • SPADL
    • Atomic-SPADL
  9. When to use kloppy vs socceraction for data loading

    master

    While socceraction provides a unified DataFrame-based model focused on on-the-ball events, kloppy is a more flexible object-based model.

    Use kloppy if:

    • You need to load data from a source not supported by socceraction.
    • You require tracking data.
    • Your analysis requires a more complete set of events beyond on-the-ball actions.

    Use socceraction if:

    • You want a streamlined, DataFrame-based workflow for on-the-ball event analysis.
    • You are using supported providers like StatsBomb, Wyscout, or Opta.
  10. Understand the concept of valuing soccer actions

    master

    In socceraction, valuing actions involves assigning a numeric value to individual on-the-ball actions (e.g., pass, dribble, interception) to quantify their contribution toward winning a game.

    Instead of valuing actions directly, the frameworks value game states. An action's usefulness $U(a_i)$ is calculated as the difference between the value of the game state immediately after the action $V(S_i)$ and the value of the game state immediately before the action $V(S_{i-1})$:

    $$U(a_i) = V(S_i) - V(S_{i-1})$$

    Differences between implemented frameworks depend on:

    1. State Representation: How the game state $S_i$ is defined (e.g., ball location, score difference).
    2. Value Assignment: How the value $V$ is assigned to that specific state.

    Prerequisites: Before using these frameworks, you must have:

    1. Collected soccer event data.
    2. Converted the data into the SPADL format.
  11. Organize local StatsBomb data files

    master

    When using getter="local", your data directory must follow the same hierarchy as the StatsBomb Open Data repository:

    root
    ├── competitions.json
    ├── events
    │   ├── <match_id>.json
    │   └── ...
    ├── lineups
    │   ├── <match_id>.json
    │   └── ...
    ├── matches
    │   ├── <competition_id>
    │   │   └── <season_id>.json
    │   │   └── ...
    │   └── ...
    └── three-sixty
        ├── <match_id>.json
        └── ...
  12. Understand the Atomic-VAEP concept and feature encoding

    master

    Atomic-VAEP is an extension of the VAEP (Valuing Actions by Estimating Probabilities) framework that uses the Atomic-SPADL representation. Unlike standard SPADL, Atomic-SPADL removes the 'result' attribute from actions. This prevents the model from unfairly penalizing an action provider for the outcome of a recipient's subsequent action (e.g., a pass being 'failed' due to a poor touch by the receiver).

    Key benefits include:

    • Improved Shot Valuation: Assigns shots values closer to their xG (expected goals) score, preventing outliers (like a single lucky goal) from disproportionately skewing a player's total VAEP score.
    • Increased Stability: Produces more robust player ratings over a season by reducing the impact of luck-based outcomes.

    By default, Atomic-VAEP encodes a game state $S_i$ using the current action and the two preceding actions: $S_i = {a_{i-2}, a_{i-1}, a_i}$.