Kalman Filter: Simple but Powerful
A friendly, intuitive explanation of Kalman Filters. No heavy measure theory, just state estimates and noise.
Here is a confession: I don't really watch football.
I couldn't tell you the difference between a double pivot and a false nine. I don't know who the manager of Aston Villa is, and until recently, I thought "clean sheet" was a laundry term.
But last month, I stood victorious at the top of my office Fantasy Premier League (FPL) group, holding a trophy and looking down at twelve of my football-obsessed friends who spend their weekends screaming at the TV.
How did I do it?
I didn't watch games, read sports blogs, or follow Twitter transfer rumors. Instead, I locked Erling Haaland in my squad, treated FPL as a constrained linear programming problem, wrote a custom solver, and let math do the rest.
I call it the FPL Geek method. Here is how it works.
Fantasy Premier League is deceptively simple:
Most people play FPL using their gut. They transfer in a player because they "looked sharp last weekend" or drop a defender because they have a bad feeling.
To a data scientist, however, this isn't a game of vibes. It's a Multi-dimensional Knapsack Problem with Logic Constraints.
We want to select a subset of players that maximizes our objective function (expected points, or xP) subject to budget constraints, positional requirements, and team limits.
In optimization theory, you can simplify problems by fixing "obviously optimal" variables.
In FPL, Erling Haaland is that variable. He is a statistical anomaly—a goal-scoring machine who plays for one of the most dominant attacking teams in the world. He is extremely expensive, but his expected points are so high that over the course of a season, not owning him is a statistical suicide.
So I added a hard constraint to my model:
$x_{\text{Haaland}} = 1 \quad (\text{Always})$ $\text{Captain} = \text{Haaland} \quad (\text{Usually})$
With Haaland taking up roughly $15%$ of my budget, my actual problem was: How do I optimize the remaining £85m across 14 roster slots?
To build my FPL helper, FPL Geek, I split the logic into two parts: data prediction and squad optimization.
First, I pulled player stats, historical performance, fixture difficulty, and injury reports. I built a simple model to predict how many points every player in the league would score over the next 3 to 5 gameweeks. This gave me my $xP_i$ (expected points for player $i$).
Once we have the predicted points ($xP_i$) and prices ($w_i$), we feed them into our solver. In FPL Geek, the core optimization is written in TypeScript on the frontend (using custom combinatorics to run instantly in the browser) and Python on the backend (using scipy.optimize and mixed-integer linear programming).
Here is a simplified view of the math behind the lineup optimizer:
$\max \sum_{i \in \text{Players}} xP_i \cdot s_i$
Subject to:
Here is a snippet of how the frontend solver.ts optimizes transfer allowances:
export function optimizeWithAllowance(
currentSquad: Player[],
bank: number,
allCandidates: Player[],
transferAllowance: number,
lockedIds: number[]
): OptimizationResult {
// Phase 1: Identify best XI combinations using N transfers
// Phase 2: Fill the remaining bench positions within budget constraints
// Phase 3: Rank results by net xP gain (taking transfer point hits into account)
...
}
By letting the solver make my decisions, I avoided the classic traps that sink human managers:
When Marcus Rashford went on a cold streak, human managers kept him because "he's bound to score soon." My solver looked at his dipping xP and cut him immediately for a rising differential. The solver doesn't care about a player's history or reputation; it only cares about the gradient.
Humans panic-transfer players on Sunday night after they score a brace. The solver always waited until Friday afternoon, incorporating the latest injury news and price changes before making a move.
A huge part of FPL is managing your bench. The FPL Geek optimizer doesn't just pick the best XI; it optimizes the bench for rotation, ensuring that if one of my starters gets benched unexpectedly, a cheap but active player from Burnley or Luton steps in to grab 4 crucial points.
On the final day of the season, while my friends were debating whether to start three defenders or play a risky wildcard, I loaded the latest projections into the solver, hit "⚡ Optimize", clicked "Apply", and went for a run.
My captain Haaland scored a hat-trick, my cheap differentials returned clean sheets, and I won the league by a comfortable margin of 42 points.
You don't need to live and breathe football to win at FPL. You just need to realize that behind the grass, the fans, and the pundits, football is a numbers game. And if you know how to talk to the numbers, the numbers will tell you how to win.
I'd love to hear your thoughts or questions. Connect with me on LinkedIn or send me an email!