Predicting Goal Probability for Individual Soccer Shots
Machine LearningModel answerLast updated
Design a calibrated probability model that estimates how likely each soccer shot is to score, covering feature design, sparse regions, proper loss functions and calibration.
Context
You are building a shot-quality model for a soccer analytics team. For every shot, the model should output the probability that it ends in a goal. This is often called an "expected goals" score.
Data
You have about 500,000 historical shots from professional leagues. Each row contains:
shot_coordinates: the (x, y) position of the shot on a 105 m by 68 m pitchangle_to_goal: the shooting angle measured relative to the goal's centerdistance_to_goal: straight-line distance to the goal's centerdefender_proximity: distance to the closest defenderis_header: whether the shot was a headergame_minute: the minute of the matchgoal_scored: the binary label (1 = goal)
Questions
- Modeling and features. Describe the model you would use to estimate
P(goal = 1 | features). Explain how you would turn the raw coordinates into features that capture the non-linear link between shot location and scoring chance. - Sparse regions. Some locations (very wide angles, very long range) have only a handful of past shots. How do you keep the model from producing unreliable estimates there?
- Loss and metrics. Which training loss would you choose? Explain why plain accuracy, and possibly mean squared error, are inadequate for this task.
- Calibration. How would you make sure that, among 1,000 shots predicted at roughly 0.20, about 200 actually result in goals? Describe the procedure and how you would verify it.
Answer as you would in a technical discussion: give a clear strategy, justify the trade-offs, and mention pitfalls you would guard against.
Hints
Hint 1
Think geometrically: what a shooter actually sees is the portion of the goal mouth between the two posts, not the line to the goal's center. Also, the pitch is left-right symmetric around the goal.
Hint 2
Scoring chance changes quickly close to goal and levels off far away, so consider log-transformed distance, interactions (e.g. header with distance), and shape constraints such as monotonicity to stay sensible where data is thin.
Hint 3
Goals are rare (~10%), so a threshold-based metric hides everything interesting. Use a proper scoring rule for training, then fit a separate calibrator on held-out data split by time, and check calibration overall and within subgroups.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing
This is a probability estimation task, not a classification task. The output is used as a number (summed over a match, compared across players), so ranking is not enough: the values themselves must be trustworthy. Every design choice below follows from that.
1. Modeling strategy and features
Baseline. Logistic regression on well-designed features. It is interpretable, fast, and forces careful feature thinking, which is where most of the signal lives.
Main model. Gradient-boosted trees (LightGBM or XGBoost) with a binary log-loss objective, shallow depth, and monotonic constraints. Compare against the baseline on a time-held-out season, then calibrate.
Coordinate transformations
-
Orient attacks. Flip coordinates so every shot attacks the same goal, centered at (105, 34).
-
Fold symmetry. Use
|y − 34|. A shot from the left and its mirror image are equivalent, which effectively doubles the data per location. -
Visible goal angle. Use the angle subtended by the two posts rather than the angle to the center. With goal width
w = 7.32,dx = 105 − x,dy = y − 34:θ = atan2(w·dx, dx² + dy² − (w/2)²)This is usually the single strongest feature, and it shrinks smoothly to zero near the byline and far out.
-
Log distance. Probability drops steeply near goal and flattens at range, so
log(d)makes the relationship much closer to linear on the logit scale. -
Interactions.
θ × log d,is_header × d(headers lose value faster with distance), anddefender_proximity × θ. -
Splines on
dandθif you stay in a GLM/GAM setting.
import numpy as np
GX, GY, GW = 105.0, 34.0, 7.32
def shot_features(x, y, is_header, defender_prox):
dx = GX - x
dy = np.abs(y - GY)
dist = np.hypot(dx, dy)
theta = np.arctan2(GW * dx, dx**2 + dy**2 - (GW / 2) ** 2)
theta = np.clip(theta, 0, np.pi)
ld = np.log1p(dist)
return {
"dist": dist, "log_dist": ld, "vis_angle": theta,
"angle_x_logdist": theta * ld,
"header_x_dist": is_header * dist,
"def_prox": defender_prox,
"def_x_angle": defender_prox * theta,
"is_header": is_header,
}
game_minute is likely weak on its own; keep it but do not expect much importance.
2. Sparse regions
A flexible model can assign inflated probabilities to a region because two lucky goals happened there. Countermeasures:
- Physically meaningful features (
θ,log d) extrapolate smoothly, unlike a raw grid of coordinates. - Monotonic constraints: probability non-increasing in distance, non-decreasing in visible angle. This removes unphysical bumps.
- Regularization: large minimum leaf size (for example 200 or more samples), shallow trees, L2 penalties; or a penalized GAM.
- Partial pooling: if you use spatial bins, shrink each bin's rate toward a global estimate, for example
(goals + α) / (shots + α + β)with an empirical-Bayes Beta prior. - Pool more data: symmetry folding and multiple leagues (with a league indicator).
- Report uncertainty: calibration plots with confidence intervals per distance and angle band show where the model should not be trusted.
3. Loss function
Train on log-loss (Bernoulli negative log-likelihood):
L = −(1/N) Σ [ yᵢ log pᵢ + (1 − yᵢ) log(1 − pᵢ) ]
It is a strictly proper scoring rule: expected loss is minimized only when the predicted probability equals the true one, which is exactly the objective.
Why accuracy is inadequate
- With about 10% positives, always predicting "no goal" yields roughly 90% accuracy while carrying no information.
- It needs a threshold and discards the probability. A 0.04 shot and a 0.45 shot both map to "no goal", though distinguishing them is the whole purpose.
Why MSE is only partly adequate
- As a regression loss on an unbounded linear output, it can yield values outside [0, 1].
- On probabilities it equals the Brier score, which is proper and a good evaluation metric (it decomposes into reliability, resolution, uncertainty). But its penalty is bounded, so it barely separates 0.01 from 0.05 on rare events and treats confident mistakes mildly. Log-loss punishes overconfidence harshly and has better gradients for logistic models.
Recommendation: optimize log-loss; report log-loss, Brier score, ROC-AUC (ranking only), and calibration diagnostics.
4. Calibration
- Split by time. Train on earlier seasons, fit the calibrator on a later held-out slice, test on the most recent season. Random splits leak match and team correlation. Out-of-fold predictions are an alternative.
- Diagnose. Draw a reliability diagram (quantile bins), compute expected calibration error, and check calibration-in-the-large:
ΣpversusΣy. - Fit a calibrator.
- Platt scaling:
p' = σ(a·logit(p) + b). Two parameters, robust, good for smooth sigmoid-shaped distortion. - Isotonic regression: flexible monotone mapping; suited to large calibration sets (roughly 50k+), but can be step-like and overfit in sparse high-probability regions.
- Platt scaling:
- Verify the 0.20 requirement. For 1,000 shots near 0.20, the expected goal count is 200 with standard deviation
√(1000 × 0.2 × 0.8) ≈ 12.6. Counts of about 175 to 225 are consistent with good calibration; values well outside that (beyond ~2σ) signal miscalibration. - Check subgroups. Headers versus feet, distance bands, leagues. A model can be calibrated overall yet biased for headers; add interactions or calibrate per segment if data permit.
Common mistakes
- Feeding raw
(x, y)linearly, or using the angle to the goal center instead of the visible angle. - Reporting accuracy or tuning a threshold for a probability product.
- Fitting the calibrator on training data.
- Random splits across matches and seasons.
- Letting a high-capacity model chase noise in sparse areas without constraints.
- Including any feature recorded after the shot outcome (for example a "saved" flag), which leaks the label.