← All work
Project · Machine learning

Player similarity with K-nearest neighbours

A player similarity experiment — and my favourite way to introduce traditional machine learning, because you can see exactly how the algorithm makes its decisions.

K-nearest neighboursMachine learningFeature scalingPythonFootball data
Try the live app ↗Play with the demo
The problem

Who plays like this player?

Imagine you want to find players who play similarly to a particular footballer.

How could a computer identify players with similar characteristics?

The idea

Measure the distance between players

Use K-nearest neighbours (KNN) to compare players based on selected performance characteristics. Each player becomes a point in “feature space”, and the closest points are the most similar players.

For example

PlayerGoals per gameAssists per gamePasses per game
Player A0.80.512
Player B0.70.611
Player C0.20.120
Player D0.90.413

Player A, B and D look alike: lots of goals and assists, few passes. Player C is very different. KNN turns that intuition into maths.

How KNN works

Three steps

  1. Choose the features

    Pick the stats that describe a player's style, like goals, assists and passes per game.

  2. Calculate distances

    Treat each player as a point and measure the straight-line distance from your chosen player to every other player.

  3. Pick the K closest

    Sort by distance. The K nearest players — the “neighbours” — are the most similar.

distance = √( (goalsA − goalsB)² + (assistsA − assistsB)² + (passesA − passesB)² ) ← smaller = more similar
Interactive demo

Find similar players yourself

Choose a player, the stats to compare and how many neighbours (K) to find. Then switch feature scaling off and watch the results change.

3
Features to compare
Chart axes

Player characteristics

Scatter plot of the twelve example players. The full values are in the data table below the chart.

Distance is measured across all the features you've ticked — the chart shows two of them. Hover over a player for their stats.

Most similar players

    See all the data
    PlayerGoals per gameAssists per gamePasses per game
    Player A0.80.512
    Player B0.70.611
    Player C0.20.120
    Player D0.90.413
    Player E0.60.318
    Player F0.10.245
    Player G0.30.438
    Player H0.050.0555
    Player I0.40.730
    Player J0.750.4515
    Player K0.150.350
    Player L0.10.113

    These are made-up example players for the demo. Players A–D match the example table above.

    Why feature scaling matters

    One stat can quietly take over

    Goals, assists and passes are measured on very different ranges. Without scaling, the stat with the biggest numbers dominates the distance — and the “most similar” players are really just the players with a similar number of passes.

    The ranges in this data

    How far each stat spreads across the 12 example players:

    Goals per game
    Assists per game
    Passes per game

    A gap of 5 passes counts the same as a gap of 5 goals per game — which no player could ever have.

    The fix: rescale first

    Min–max scaling squeezes every stat onto the same 0–1 range, so each one gets a fair say in the distance.

    scaled = (value − min) ÷ (max − min)

    Try it in the demo: choose Player A and switch scaling off. Player L — who barely scores or assists — suddenly looks like one of the most similar players, just because their pass count is close.

    The educational takeaway

    Machine learning you can see

    KNN is one of the most intuitive ways to understand machine learning. There's no black box: you can see every point, every distance and exactly why the algorithm picked its answer. That makes it a great first step before more complex models.

    An important detail

    An experiment, not a scouting model

    This is a player similarity experiment, not a definitive scouting or recruitment model. Similarity depends heavily on which features you choose, how you scale them, and the context players perform in — their team, league and role.

    The live app

    Try it with real players

    Search for a player and see who's most similar, then compare their stats side by side.

    Player Similarity Score app listing players similar to Leroy Sané with similarity percentagesSide-by-side stats comparison of Leroy Sané and the most similar players