Expected Threat (xT) for corners and free kicks

wa_setpieces.XTModel implements Karun Singh’s grid-based xT method: fit a grid of zone values from data, then value any pass as xT[end_zone] - xT[start_zone].

Important

The grid below is fit on a single match, purely to demonstrate the mechanism – it is far too little data for a trustworthy grid. Fit on a full season (concatenate many matches’ events) for real analysis, then reuse it with to_csv() / from_csv().

from pathlib import Path

from wa_setpieces import load_matches
from wa_setpieces.viz.plots import plot_xt_grid
from wa_setpieces.core.xt import XTModel, set_piece_delivery_xt, set_piece_xt_summary

try:
    _here = Path(__file__).resolve().parent
except NameError:
    _here = Path.cwd()
DATA = _here.parent / "tests" / "data" / "sample_match.json"

events = load_matches(DATA)

Fit the grid and look at it directly – value should climb steadily towards the opponent’s goal (x=100 in each event’s own attacking frame).

model = XTModel.fit(events, x_bins=8, y_bins=6)
fig, ax = plot_xt_grid(model)
plot 04 expected threat

xT added by every corner delivery (NaN where the corner didn’t find a teammate – there’s no reliable end location to value):

set_piece_delivery_xt(events, "corner", model)[
    ["eventId", "contestantId", "outcome", "xt_start", "xt_end", "xt_added"]
]
eventId contestantId outcome xt_start xt_end xt_added
0 191 f2yd0yzt0om6qhks9gbowu1d6 0 0.008352 0.250000 NaN
1 223 cxb4hqite921i36gwrezdts7c 1 0.023828 0.004661 -0.019166
2 404 cxb4hqite921i36gwrezdts7c 0 0.023828 0.250000 NaN
3 482 f2yd0yzt0om6qhks9gbowu1d6 0 0.008352 0.254417 NaN
4 610 f2yd0yzt0om6qhks9gbowu1d6 0 0.023828 0.254417 NaN
5 613 f2yd0yzt0om6qhks9gbowu1d6 0 0.023828 0.254417 NaN
6 723 f2yd0yzt0om6qhks9gbowu1d6 1 0.023828 0.023828 0.000000
7 730 f2yd0yzt0om6qhks9gbowu1d6 0 0.008352 0.250000 NaN
8 786 f2yd0yzt0om6qhks9gbowu1d6 0 0.023828 0.250000 NaN


Rolled up per team, for both corners and free kicks:

set_piece_xt_summary(events, "corner", model)
contestantId deliveries successful_deliveries total_xt_added avg_xt_added
0 cxb4hqite921i36gwrezdts7c 2 1 -0.019166 -0.019166
1 f2yd0yzt0om6qhks9gbowu1d6 7 1 0.000000 0.000000


set_piece_xt_summary(events, "free_kick", model)
contestantId deliveries successful_deliveries total_xt_added avg_xt_added
0 cxb4hqite921i36gwrezdts7c 12 9 0.000515 0.000057
1 f2yd0yzt0om6qhks9gbowu1d6 13 9 0.005945 0.000661


Gallery generated by Sphinx-Gallery