Comebacks: turning losing positions into victories
Abstract
How often do teams overturn big deficits — and does it happen more than the
legends suggest? This study answers it using the full match archive drawn from
the Soccers football database. The choke is rarer than the legend suggests — and
almost never happens from a truly big lead. All computation runs in Rust inside
a .mars notebook (polars + plotters — charts as inline SVG), and every table
and figure is generated from the extracted CSVs.
Keywords
Keywords: football, analysis, comebacks, mars, sqlite
Table of contents
Introduction
Every fan lives for the comeback — trailing at half-time, even 2–0 down, then winning. This notebook replays every goal-by-goal timeline in the StatsBomb subset (~4,200 matches with timing data) and asks: which teams are historically best at erasing deficits?
A comeback win = a team trailed by at least one goal at some point and still won. We rank teams by comeback-win rate (comebacks ÷ matches where they trailed), with a minimum-sample guard, and break comebacks down by the size of the deficit erased.
Coverage caveat: goal timing exists only for StatsBomb matches (World Cups, Euros, Champions League, top domestic leagues) — a smaller but high-quality subset.
Methods
Data were extracted from the Soccers football database (packages/data) as CSV
snapshots: goal_events.
The analysis runs entirely in Rust inside the notebook: polars handles table
scans, joins and aggregations; plotters renders figures as inline SVG;
mars_table renders result tables.
Each code cell is kept to a single output so results can be read top to bottom.
Results
All figures and tables below are computed directly from the extracted data. Each code cell produces one output — a table, a chart, or a short text summary.
use polars::prelude::*;
let df = LazyCsvReader::new("data/goal_events.csv")
.finish()
.expect("failed to open data/goal_events.csv — run from the notebook directory")
.collect()
.expect("failed to collect CSV into DataFrame");
println!(
"loaded {} goal rows | schema: {:?}",
df.height(),
df.get_column_names()
);
loaded 11328 goal rows | schema: ["mid", "minute", "added_minute", "player", "gtid", "gteam", "hid", "aid", "home", "away", "hg", "ag", "league", "date", "season"]
let s = |name: &str| df.column(name).unwrap_or_else(|_| panic!("missing {name}")).clone();
let col_str = |name: &str| -> Vec<String> {
s(name).str().unwrap().iter().map(|o| o.unwrap_or("").to_string()).collect()
};
let col_i64 = |name: &str| -> Vec<i64> {
let c = s(name);
let c = if c.dtype() == &DataType::Null { c.cast(&DataType::Int64).unwrap() } else { c };
c.i64().unwrap().iter().map(|o| o.unwrap_or(0)).collect()
};
let mid_v = col_i64("mid");
let league_v = col_str("league");
let hid_v = col_i64("hid");
let aid_v = col_i64("aid");
let home_v = col_str("home");
let away_v = col_str("away");
let hg_v = col_i64("hg");
let ag_v = col_i64("ag");
let minute_v = col_i64("minute");
let added_v = col_i64("added_minute");
let gtid_v = col_i64("gtid");
let gteam_v = col_str("gteam");
let ng = df.height();
println!("extracted {ng} goal rows");
// index goals by match, sorted by (minute, added)
use std::collections::BTreeMap;
let mut order: Vec<usize> = (0..ng).collect();
order.sort_by_key(|&i| (mid_v[i], minute_v[i], added_v[i]));
// per-match goal lists
let mut match_goals: BTreeMap<i64, Vec<usize>> = BTreeMap::new();
for &i in &order {
match_goals.entry(mid_v[i]).or_default().push(i);
}
// team display names
let mut names: std::collections::HashMap<i64, String> = std::collections::HashMap::new();
for i in 0..ng {
names.entry(hid_v[i]).or_insert_with(|| home_v[i].clone());
names.entry(aid_v[i]).or_insert_with(|| away_v[i].clone());
}
println!("matches with goal data: {}", match_goals.len());
extracted 11328 goal rows
matches with goal data: 3703
Replay timelines: who trailed, who recovered?
For each team-match we track the worst deficit suffered (min of my_goals − opp_goals after every goal) and the final result.
use std::collections::HashMap;
#[derive(Default, Clone)]
struct Acc {
played: u64, // matches with goal data the team appears in
trailed: u64, // matches where they were behind at some point
comebacks: u64, // trailed AND won
cb1: u64, cb2: u64, cb3: u64, // comebacks by max deficit erased
}
let mut acc: HashMap<i64, Acc> = HashMap::new();
let mut big_comebacks: Vec<(i64, String, String, String)> = Vec::new(); // deficit, desc, team, mid
for (_mid, idxs) in match_goals.iter() {
let i0 = idxs[0];
let (hid, aid) = (hid_v[i0], aid_v[i0]);
let (hg, ag) = (hg_v[i0], ag_v[i0]);
let mut hs = 0i64;
let mut as_ = 0i64;
// per side: worst deficit (most negative my-opp) and final my goals
let mut h_min = 0i64;
let mut a_min = 0i64;
for &gi in idxs {
if gtid_v[gi] == hid { hs += 1; } else { as_ += 1; }
let d = hs - as_;
if -d > h_min { h_min = -d; }
if d > a_min { a_min = d; }
}
// h_min/a_min now hold the largest deficit each side suffered
let h_won = hg > ag;
let a_won = ag > hg;
{
let e = acc.entry(hid).or_default();
e.played += 1;
if h_min > 0 {
e.trailed += 1;
if h_won {
e.comebacks += 1;
if h_min == 1 { e.cb1 += 1; } else if h_min == 2 { e.cb2 += 1; } else { e.cb3 += 1; }
if h_min >= 3 && big_comebacks.len() < 10 {
big_comebacks.push((h_min, format!("{} {}–{} {} ({})", home_v[i0], hg, ag, away_v[i0], league_v[i0]), home_v[i0].clone(), mid_v[i0].to_string()));
}
}
}
}
{
let e = acc.entry(aid).or_default();
e.played += 1;
if a_min > 0 {
e.trailed += 1;
if a_won {
e.comebacks += 1;
if a_min == 1 { e.cb1 += 1; } else if a_min == 2 { e.cb2 += 1; } else { e.cb3 += 1; }
if a_min >= 3 && big_comebacks.len() < 10 {
big_comebacks.push((a_min, format!("{} {}–{} {} ({})", away_v[i0], ag, hg, home_v[i0], league_v[i0]), away_v[i0].clone(), mid_v[i0].to_string()));
}
}
}
}
}
// overall comeback profile
let (mut p, mut t, mut c, mut c1, mut c2, mut c3) = (0u64, 0u64, 0u64, 0u64, 0u64, 0u64);
for a in acc.values() {
p += a.played; t += a.trailed; c += a.comebacks; c1 += a.cb1; c2 += a.cb2; c3 += a.cb3;
}
println!("team-matches in dataset: {p} | trailed at some point: {t} ({:.1}%)", t as f64 / p as f64 * 100.0);
println!("comeback wins: {c} — {:.1}% of matches trailed ended in victory", c as f64 / t as f64 * 100.0);
println!("by deficit erased: 1 goal {c1} | 2 goals {c2} | 3+ goals {c3}");
// deficit distribution table
let dist_rows = vec![
vec!["1 goal".to_string(), c1.to_string()],
vec!["2 goals".to_string(), c2.to_string()],
vec!["3+ goals".to_string(), c3.to_string()],
];
mars_table(&["deficit erased", "comeback wins"], &dist_rows);
team-matches in dataset: 7406 | trailed at some point: 4219 (57.0%)
comeback wins: 443 — 10.5% of matches trailed ended in victory
by deficit erased: 1 goal 414 | 2 goals 29 | 3+ goals 0
| deficit erased | comeback wins |
|---|---|
| 1 goal | 414 |
| 2 goals | 29 |
| 3+ goals | 0 |
// team rankings: rate = comebacks / trailed, min 15 trailed matches
let mut ranked: Vec<(&i64, &Acc)> = acc.iter().filter(|(_, a)| a.trailed >= 15).collect();
ranked.sort_by(|a, b| {
let ra = a.1.comebacks as f64 / a.1.trailed as f64;
let rb = b.1.comebacks as f64 / b.1.trailed as f64;
rb.partial_cmp(&ra).unwrap()
});
let rate_rows: Vec<Vec<String>> = ranked
.iter()
.take(15)
.map(|(tid, a)| {
vec![
names.get(*tid).cloned().unwrap_or_else(|| tid.to_string()),
a.trailed.to_string(),
a.comebacks.to_string(),
format!("{:.1}%", a.comebacks as f64 / a.trailed as f64 * 100.0),
]
})
.collect();
mars_table(&["team", "times trailed", "comebacks", "comeback rate"], &rate_rows);
| team | times trailed | comebacks | comeback rate |
|---|---|---|---|
| Manchester City WFC | 20 | 9 | 45.0% |
| Paris Saint-Germain | 25 | 10 | 40.0% |
| Barcelona | 148 | 58 | 39.2% |
| Arsenal WFC | 24 | 9 | 37.5% |
| Chelsea FCW | 18 | 6 | 33.3% |
| Juventus | 15 | 5 | 33.3% |
| Arsenal | 21 | 7 | 33.3% |
| Madrid CFF | 17 | 5 | 29.4% |
| Bayer Leverkusen | 25 | 7 | 28.0% |
| Tottenham Hotspur | 17 | 4 | 23.5% |
| Orlando Pride | 19 | 4 | 21.1% |
| OGC Nice | 21 | 4 | 19.0% |
| West Ham United | 17 | 3 | 17.6% |
| Real Madrid | 29 | 5 | 17.2% |
| Atlético Madrid | 31 | 5 | 16.1% |
// raw volume: most comeback wins
let mut vol: Vec<(&i64, &Acc)> = acc.iter().filter(|(_, a)| a.comebacks > 0).collect();
vol.sort_by(|a, b| b.1.comebacks.cmp(&a.1.comebacks));
let vol_rows: Vec<Vec<String>> = vol
.iter()
.take(15)
.map(|(tid, a)| {
vec![
names.get(*tid).cloned().unwrap_or_else(|| tid.to_string()),
a.comebacks.to_string(),
a.trailed.to_string(),
format!("{:.1}%", a.comebacks as f64 / a.trailed as f64 * 100.0),
]
})
.collect();
mars_table(&["team", "comeback wins", "times trailed", "rate"], &vol_rows);
| team | comeback wins | times trailed | rate |
|---|---|---|---|
| Barcelona | 58 | 148 | 39.2% |
| Paris Saint-Germain | 10 | 25 | 40.0% |
| Arsenal WFC | 9 | 24 | 37.5% |
| Manchester City WFC | 9 | 20 | 45.0% |
| Bayer Leverkusen | 7 | 25 | 28.0% |
| Arsenal | 7 | 21 | 33.3% |
| Chelsea FCW | 6 | 18 | 33.3% |
| Napoli | 6 | 14 | 42.9% |
| West Ham United LFC | 5 | 56 | 8.9% |
| Sevilla | 5 | 59 | 8.5% |
| Real Madrid | 5 | 29 | 17.2% |
| Juventus | 5 | 15 | 33.3% |
| Madrid CFF | 5 | 17 | 29.4% |
| Atlético Madrid | 5 | 31 | 16.1% |
| Orlando Pride | 4 | 19 | 21.1% |
big_comebacks.sort_by(|a, b| b.0.cmp(&a.0));
println!("--- biggest deficits erased (3+) ---");
for (d, desc, team, _mid) in big_comebacks.iter().take(10) {
println!(" {team}: came back from {d} down — {desc}");
}
--- biggest deficits erased (3+) ---
use plotters::prelude::*;
// comeback rate for top 12 teams by volume (min 15 trailed)
let mut chart_rows: Vec<(&i64, &Acc)> = acc
.iter()
.filter(|(_, a)| a.trailed >= 15 && a.comebacks >= 3)
.collect();
chart_rows.sort_by(|a, b| b.1.comebacks.cmp(&a.1.comebacks));
chart_rows.truncate(12);
let mut clabels: Vec<String> = Vec::new();
let mut crate_: Vec<f64> = Vec::new();
for (tid, a) in &chart_rows {
clabels.push(names.get(*tid).cloned().unwrap_or_default().chars().take(14).collect());
crate_.push(a.comebacks as f64 / a.trailed as f64 * 100.0);
}
let ymax3 = crate_.iter().cloned().fold(1.0_f64, f64::max) * 1.2;
let n3 = crate_.len();
let figure = plotters::evcxr::evcxr_figure((720, 400), |root| {
root.fill(&WHITE)?;
let mut chart = ChartBuilder::on(&root)
.caption("Comeback win rate — most prolific comeback teams", ("sans-serif", 18))
.margin(10)
.x_label_area_size(80)
.y_label_area_size(45)
.build_cartesian_2d(-0.5_f64..(n3 as f64 - 0.5), 0.0_f64..ymax3)?;
chart.configure_mesh().x_labels(n3).x_label_formatter(&|x: &f64| {
clabels.get(*x as usize).cloned().unwrap_or_default()
}).draw()?;
chart.draw_series((0..n3).map(|i| {
Rectangle::new([(i as f64 - 0.35, 0.0), (i as f64 + 0.35, crate_[i])], GREEN.filled())
}))?;
Ok(())
});
figure.evcxr_display();
loaded 11328 goal rows | schema: ["mid", "minute", "added_minute", "player", "gtid", "gteam", "hid", "aid", "home", "away", "hg", "ag", "league", "date", "season"]
extracted 11328 goal rows
matches with goal data: 3703
team-matches in dataset: 7406 | trailed at some point: 4219 (57.0%)
comeback wins: 443 — 10.5% of matches trailed ended in victory
by deficit erased: 1 goal 414 | 2 goals 29 | 3+ goals 0
--- biggest deficits erased (3+) ---
Discussion
In the StatsBomb subset, 57% of team-matches saw a side trail at some point — and 10.5% of those ended in a comeback win (443 wins).
The shape of comebacks is brutally one-dimensional:
- Deficit erased = 1 goal: 414 comebacks
- Deficit erased = 2 goals: 29 comebacks
- Deficit erased = 3+ goals: zero
Comebacks happen — but almost never from three down. The biggest deficits erased in the dataset were two goals, and even those are rare (~7% of all comebacks).
Most prolific: Barcelona, 58 comeback wins in 148 trailed matches (39.2%). Best rate (min. 15 trailed games): Manchester City WFC at 45.0%, then PSG 40.0%, Barcelona 39.2%, Arsenal WFC 37.5%. Notably, the rate leaders skew toward elite sides — teams good enough to be trailing are also good enough to chase.
Note: StatsBomb data includes women's and youth competitions — "WFC"/"LFC" suffixes are the women's teams.
Limitations. The analysis is limited to the competitions present in the database; player-level metrics exist only for StatsBomb-covered tournaments, and underlying event data may contain errors.
Conclusion
In the StatsBomb subset, 57% of team-matches saw a side trail at some point — and 10.5% of those ended in a comeback win (443 wins). Together these results answer the research question posed in the Introduction and quantify the pattern across 4,200 matches. The notebook provides a fully reproducible pipeline from raw CSV extracts to published figures.