Calculating xG in football involves estimating the probability of a shot resulting in a goal based on the specific characteristics of the chance. The model analyses historical shot data and considers variables such as distance, angle, type of shot, preceding pass and defensive context to assign each attempt a value between 0 and 1.

This value does not simply describe where the shot was taken from. xG models turn spatial and contextual data into a probability of scoring, meaning that two shots from similar positions can receive different values. Understanding this process means first examining the data involved, how it is converted into variables and how the model learns the relationship between these variables and the likelihood of scoring.

What Data and Models Do You Need to Calculate xG in Football?

To calculate xG in football, you need a well-structured dataset of historical shots and a model capable of turning the characteristics of each chance into a probability of scoring. The accuracy of the calculation depends on the quality of the data, the variables describing each shot and the model’s ability to identify how these relate to scoring a goal.

The process follows a straightforward sequence. Each shot is recorded along with its coordinates and context. These observations are then converted into variables that the model can interpret, before the system produces a probability. This probability represents the shot’s xG value. A shot rated at 0.30 xG represents a chance that the model estimates has approximately a 30% probability of resulting in a goal under comparable circumstances.

The key point is that the football analyst does not assign this value manually. The model learns from thousands of shots labelled as either goals or non-goals, identifying relationships between variables such as distance, angle, body part used, type of assist and defensive pressure.

This article explains how to calculate xG in football using data, probabilistic models, contextual variables, machine learning and statistical validation

The technical process for calculating xG can therefore be summarised as follows:

1
Shot

The shot and its location are recorded.

2
Variables

Distance, angle and context are extracted.

3
Model

The algorithm processes the shot’s characteristics.

4
xG Probability

The model assigns a probability between 0 and 1.

5
Validation

The quality of the predicted probabilities is assessed.

Which Variables Are Used to Calculate xG in Football?

The xG value depends on the variables that describe the chance before the shot is taken. Expected goals models do not simply analyse the position of the shot. They combine geometry, finishing technique and defensive context to estimate the probability of scoring more accurately.

The most relevant variables are usually grouped into several categories:

  • Shot location: Coordinates pinpoint exactly where the shot is taken and provide the basis for calculating other derived variables.
  • Distance from goal: The greater the distance between the shooting position and the goal line, the lower the probability of scoring tends to be.
  • Shooting angle: A shot from a central position offers a wider view of the goal than one taken from a tight angle.
  • Body part used: Models distinguish between shots taken with the foot, headers and other types of finishes because they have different conversion rates.
  • Type of assist: A cut-back, cross, through ball or second-phase attack creates different shooting situations.
  • Game situation: The model distinguishes between open play, counter-attacks, corners, direct free kicks and penalties.
  • Defensive pressure: The distance to the nearest defender, the possibility of a block and the number of players between the ball and the goal all affect how difficult the shot is.
  • Goalkeeper positioning: When tracking data is available, the goalkeeper’s position provides additional information about the space available and how much of the goal is covered.

These variables explain why two shots taken from almost exactly the same area do not necessarily have the same xG value. A clean shot following a cut-back and another taken under pressure from the same position represent different situations. The next step is to turn all this information into a measurable probability.

How Are Distance, Angle and Context Converted into a Probability of Scoring?

The calculation begins with the exact position from which the shot is taken. Using its coordinates, the model calculates geometric variables such as the distance to the goal and the angle between the two goalposts. These measurements describe an essential part of the chance, although they do not fully explain how difficult it is to score.

One way to understand how these variables are converted into xG is through logistic regression. This model converts different shot characteristics into a probability between 0 and 1 using the following function:

P(gol) = 1 / (1 + e-z)

The value of z combines the available information about the shot:

z = β0 + β1d + β2θ + β3X3 + … + βnXn

In this expression, d represents the distance and θ the shooting angle. The X variables include additional information such as the body part used, type of assist, defensive pressure and goalkeeper positioning. The β coefficients are not assigned manually. Instead, the model learns them during training from historical shots labelled as either goals or non-goals.

A practical example makes the difference easier to understand. A shot from a central position inside the penalty area, following a cut-back and with no defender nearby, offers more favourable geometric and contextual conditions than a shot taken from a wider angle, further from goal and under pressure. The model processes these differences and assigns a different probability to each attempt, rather than relying on fixed values based solely on shot location.

The final probability represents the shot’s xG value. When multiple shots belong to the same player, team or match, their probabilities are added together to calculate the cumulative xG and measure the overall quality of the chances created.

What Data and Models Do You Need to Calculate xG in Football

How Is an xG Model Trained Using Historical Shot Data?

Training an xG model in football starts with a large dataset of historical shots labelled according to their outcome. Each shot becomes an individual observation, and the target variable is binary, where goal = 1 and no goal = 0. Using this data, the model learns which combinations of characteristics are associated with a higher or lower probability of scoring.

Before training the algorithm, a process known as feature engineering takes place. This involves transforming raw data into variables that the model can use to learn patterns. Shot coordinates are converted into measurements such as distance and angle, while categorical features such as shot type, cut-backs, crosses, set pieces and the body part used are encoded so the model can interpret them correctly.

Not all algorithms perform equally well for this task. The choice depends on the volume of data, the complexity of the variables and the level of interpretability required for the analysis.

Model Use in xG Calculation Main Strength
Logistic Regression Baseline probability of scoring Interpretability
GAM Non-linear relationships Balance between accuracy and interpretability
Gradient Boosting Complex interactions Predictive power
XGBoost Large structured datasets Performance and scalability
Neural Networks Complex spatial context Advanced feature representation

Penalties, direct free kicks and other highly specific situations often require separate treatment or variables that clearly identify their characteristics, as their goal conversion rates differ from those of shots taken in open play. Training an xG model means learning these relationships from historical data, but a good fit during training does not necessarily mean that the predicted probabilities will be reliable when applied to data outside the training sample.

How to Validate Whether an xG Model Calculates Probabilities Accurately

Validating an xG model is not about checking how many goals it predicts correctly. Instead, it involves determining whether the assigned probabilities accurately reflect the actual frequency of goals scored. This distinction is essential because xG is a probabilistic metric, rather than a system that simply classifies shots as goals or non-goals.

The first step is to check calibration. If a sufficiently large group of shots receives values close to 0.20 xG, approximately 20% of those shots should result in goals. When this relationship holds across different probability ranges, the model produces estimates that can be meaningfully interpreted and compared.

Several tools are used to assess the quality of these probabilities:

  • Brier Score measures the squared difference between the estimated probability and the actual outcome of each shot.
  • Log Loss applies a particularly high penalty to overconfident predictions that turn out to be incorrect.
  • Calibration curves visually compare the probabilities generated by the model with the actual proportion of goals scored.

Evaluation must also take place using data that was not included in training. Temporal validation involves training the model on previous seasons and then testing its performance on subsequent matches, reducing the risk of evaluating only patterns the algorithm has already learnt.

Furthermore, good overall results do not guarantee consistent performance across every situation. A model might be well calibrated overall but still overestimate the probability of scoring from headers, underestimate shots taken from certain angles or make systematic errors when the goalkeeper is out of position. This is why validation should also be broken down by shooting zones, shot types and game situations.

Calculating xG in football therefore requires the ability to build, interpret and validate probabilities using statistical methods and a solid understanding of the game. These are essential skills for football data analysts and are developed further through Sports Data Campus’s MSc in Data Analytics in Football.

Want to be one of them? Fill in the form below to receive more information about the MSC Data Analytics in Football

WhatsApp contact with Pedro