socceraction.vaep.features

Implements the feature tranformers of the VAEP framework.

socceraction.vaep.features.actiontype(actions)

Get the type of each action.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The ‘type_id’ of each action.

Return type:

Features

socceraction.vaep.features.actiontype_onehot(actions)

Get the one-hot-encoded type of each action.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

A one-hot encoding of each action’s type.

Return type:

Features

socceraction.vaep.features.actiontype_result_onehot(actions)

Get a one-hot encoding of the combination between the type and result of each action.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The one-hot encoding of each action’s type and result.

Return type:

Features

socceraction.vaep.features.bodypart(actions)

Get the body part used to perform each action.

This feature generator does not distinguish between the left and right foot.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The ‘bodypart_id’ of each action.

Return type:

Features

See also

bodypart_detailed

An alternative version that splits between the left and right foot.

socceraction.vaep.features.bodypart_detailed(actions)

Get the body part with split by foot used to perform each action.

This feature generator distinguishes between the left and right foot, if supported by the dataprovider.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The ‘bodypart_id’ of each action.

Return type:

Features

See also

bodypart

An alternative version that does not split between the left and right foot.

socceraction.vaep.features.bodypart_detailed_onehot(actions)

Get the one-hot-encoded bodypart with split by foot of each action.

This feature generator distinguishes between the left and right foot, if supported by the dataprovider.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The one-hot encoding of each action’s bodypart.

Return type:

Features

See also

bodypart_onehot

An alternative version that does not split between the left and right foot.

socceraction.vaep.features.bodypart_onehot(actions)

Get the one-hot-encoded bodypart of each action.

This feature generator does not distinguish between the left and right foot.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The one-hot encoding of each action’s bodypart.

Return type:

Features

See also

bodypart_detailed_onehot

An alternative version that splits between the left and right foot.

socceraction.vaep.features.endlocation(actions)

Get the location where each action ended.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘end_x’ and ‘end_y’ location of each action.

Return type:

Features

socceraction.vaep.features.endpolar(actions)

Get the polar coordinates of each action’s end location.

The center of the opponent’s goal is used as the origin.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘end_dist_to_goal’ and ‘end_angle_to_goal’ of each action.

Return type:

Features

socceraction.vaep.features.feature_column_names(fs, nb_prev_actions=3)

Return the names of the features generated by a list of transformers.

Parameters:
  • fs (list(callable)) – A list of feature transformers.

  • nb_prev_actions (int, default=3 # noqa: DAR103) – The number of previous actions included in the game state.

Returns:

The name of each generated feature.

Return type:

list(str)

socceraction.vaep.features.gamestates(actions, nb_prev_actions=3)

Convert a dataframe of actions to gamestates.

Each gamestate is represented as the <nb_prev_actions> previous actions.

The list of gamestates is internally represented as a list of actions dataframes \([a_0,a_1,\ldots]\) where each row in the a_i dataframe contains the previous action of the action in the same row in the \(a_{i-1}\) dataframe.

Parameters:
  • actions (Actions) – A DataFrame with the actions of a game.

  • nb_prev_actions (int, default=3 # noqa: DAR103) – The number of previous actions included in the game state.

Raises:

ValueError – If the number of actions is smaller 1.

Returns:

The <nb_prev_actions> previous actions for each action.

Return type:

GameStates

socceraction.vaep.features.goalscore(gamestates)

Get the number of goals scored by each team after the action.

Parameters:

gamestates (GameStates) – The gamestates of a game.

Returns:

The number of goals scored by the team performing the last action of the game state (‘goalscore_team’), by the opponent (‘goalscore_opponent’), and the goal difference between both teams (‘goalscore_diff’).

Return type:

Features

socceraction.vaep.features.movement(actions)

Get the distance covered by each action.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The horizontal (‘dx’), vertical (‘dy’) and total (‘movement’) distance covered by each action.

Return type:

Features

socceraction.vaep.features.play_left_to_right(gamestates, home_team_id)

Perform all actions in a gamestate in the same playing direction.

This changes the start and end location of each action in a gamestate, such that all actions are performed as if the team that performs the first action in the gamestate plays from left to right.

Parameters:
  • gamestates (GameStates) – The game states of a game.

  • home_team_id (int) – The ID of the home team.

Returns:

The game states with all actions performed left to right.

Return type:

GameStates

See also

socceraction.vaep.features.play_left_to_right

For transforming actions.

socceraction.vaep.features.player_possession_time(actions)

Get the time (sec) a player was in ball possession before attempting the action.

We only look at the dribble preceding the action and reset the possession time after a defensive interception attempt or a take-on.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘player_possession_time’ of each action.

Return type:

Features

socceraction.vaep.features.result(actions)

Get the result of each action.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘result_id’ of each action.

Return type:

Features

socceraction.vaep.features.result_onehot(actions)

Get the one-hot-encode result of each action.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The one-hot encoding of each action’s result.

Return type:

Features

socceraction.vaep.features.simple(actionfn)

Make a function decorator to apply actionfeatures to game states.

Parameters:

actionfn (callable) – A feature transformer that operates on actions.

Returns:

A feature transformer that operates on game states.

Return type:

FeatureTransfomer

socceraction.vaep.features.space_delta(gamestates)

Get the distance covered between the last and previous actions.

Parameters:

gamestates (GameStates) – The gamestates of a game.

Returns:

A dataframe with a column for the horizontal (‘dx_a0i’), vertical (‘dy_a0i’) and total (‘mov_a0i’) distance covered between each <nb_prev_actions> action ai and action a0.

Return type:

Features

socceraction.vaep.features.speed(gamestates)

Get the speed at which the ball moved during the previous actions.

Parameters:

gamestates (GameStates) – The game states of a game.

Returns:

A dataframe with columns ‘speedx_a0i’, ‘speedy_a0i’, ‘speed_a0i’ for each <nb_prev_actions> containing the ball speed in m/s between action ai and action a0.

Return type:

Features

socceraction.vaep.features.startlocation(actions)

Get the location where each action started.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘start_x’ and ‘start_y’ location of each action.

Return type:

Features

socceraction.vaep.features.startpolar(actions)

Get the polar coordinates of each action’s start location.

The center of the opponent’s goal is used as the origin.

Parameters:

actions (SPADLActions) – The actions of a game.

Returns:

The ‘start_dist_to_goal’ and ‘start_angle_to_goal’ of each action.

Return type:

Features

socceraction.vaep.features.team(gamestates)

Check whether the possession changed during the game state.

For each action in the game state, True if the team that performed the action is the same team that performed the last action of the game state; otherwise False.

Parameters:

gamestates (GameStates) – The game states of a game.

Returns:

A dataframe with a column ‘team_ai’ for each <nb_prev_actions> indicating whether the team that performed action a0 is in possession.

Return type:

Features

socceraction.vaep.features.time(actions)

Get the time when each action was performed.

This generates the following features:
period_id:

The ID of the period.

time_seconds:

Seconds since the start of the period.

time_seconds_overall:

Seconds since the start of the game. Stoppage time during previous periods is ignored.

Parameters:

actions (Actions) – The actions of a game.

Returns:

The ‘period_id’, ‘time_seconds’ and ‘time_seconds_overall’ when each action was performed.

Return type:

Features

socceraction.vaep.features.time_delta(gamestates)

Get the number of seconds between the last and previous actions.

Parameters:

gamestates (GameStates) – The game states of a game.

Returns:

A dataframe with a column ‘time_delta_i’ for each <nb_prev_actions> containing the number of seconds between action ai and action a0.

Return type:

Features