Predict World Cup Matches Like a Pro! ⚽
Hey Future Soccer Analysts! Have you ever wondered which team might win a big match? With a little bit of code, you can make your own predictions! Let's get started with this fun project.
What's a Prediction Model and How Does It Work?
Imagine you want to predict if it will rain tomorrow. You wouldn't just guess, right? You'd look at clues like dark clouds, temperature, and past rainy days.
A Prediction Model is like a super-smart detective that uses many clues (called 'data') to make its best guess about what might happen. It learns from old data (like past soccer games) to see patterns. When we give it new information (like which teams are playing today), it uses those patterns to make a prediction. This process of using the trained model to make new guesses is called inference.
Our model has gone through three core stages:
- Training: It "studied" lots of past soccer game data to learn what makes teams win or lose.
- Validation: It took little quizzes to make sure it was learning correctly.
- Inference (What We'll Do!): Now, it's ready to put its knowledge to use and make predictions for new matches!
What You'll Need
- Google Account: Required to access and run code inside Google Colab.
- A Special File:
goal26_trained_model.pkl(This is like the 'brain' of our prediction tool!)- Download Model Make sure to download this file to your computer.
Let's Build Our Predictor!
Step 1: Start a Brand New Colab Notebook
Think of a Colab Notebook as your digital scratchpad for code. It's super easy to start:
- Go to Google Colab.
- Click on
File>New notebook.
That's it! You have a fresh new page ready for engineering.
Step 2: Upload the 'Brain' File (goal26_trained_model.pkl)
Our prediction tool needs its 'brain' to work. This brain is the file you downloaded earlier.
- On the left side of your Colab screen, look for the folder icon (📁) and click it.
- This opens the Files panel. Find the icon that looks like an arrow pointing upwards (⬆️) – that's the Upload button. Click it.
- A window will pop up. Navigate to where you saved
goal26_trained_model.pklon your computer, select it, and click Open.
💡 Note: You might see a warning stating that files will be deleted when the runtime is recycled. Don't worry, that is perfectly fine for this session!
Step 3: Copy-Paste the Magic Code!
Now, we need to add the code that loads our brain and makes predictions. Copy all the Python code below and paste it into the first code cell in your new Colab notebook.
import pandas as pd
import joblib
# =======================================================
# 1. INITIALIZE & LOAD THE TRAINED MODEL
# =======================================================
try:
# Make sure you uploaded 'goal26_trained_model.pkl' to your Colab files first
model = joblib.load('goal26_trained_model.pkl')
# Define the exact feature structure the Random Forest expects
features = ['home_rank', 'away_rank', 'home_ppg', 'away_ppg', 'is_host', 'rank_gap', 'form_gap']
print("Goal26 Inference Pipeline Loaded Successfully!")
except FileNotFoundError:
print("Error: Please upload 'goal26_trained_model.pkl' to your Colab session storage first.")
# =======================================================
# 2. CURRENT FIFA STANDINGS POWER INDEX
# =======================================================
rankings = {
'France': 1, 'Spain': 2, 'Argentina': 3, 'England': 4, 'Portugal': 5,
'Brazil': 6, 'Netherlands': 7, 'Morocco': 8, 'Belgium': 9, 'Germany': 10,
'Croatia': 11, 'Italy': 12, 'Colombia': 13, 'Senegal': 14, 'Mexico': 15,
'United States': 16, 'USA': 16, 'Uruguay': 17, 'Japan': 18, 'Switzerland': 19,
'Denmark': 20, 'Iran': 21, 'IR Iran': 21, 'South Korea': 22, 'Korea Republic': 22,
'Ecuador': 23, 'Turkiye': 24, 'Türkiye': 24, 'Austria': 25, 'Nigeria': 26,
'Australia': 27, 'Algeria': 28, 'Egypt': 29, 'Canada': 30, 'Norway': 31,
'Ukraine': 32, 'Poland': 33, 'Panama': 34, 'Ivory Coast': 35, "Côte d'Ivoire": 35,
'Wales': 37, 'Paraguay': 38, 'Scotland': 40, 'Sweden': 41, 'Haiti': 42,
'Tunisia': 44, 'Uzbekistan': 50, 'Qatar': 56, 'South Africa': 60, 'Saudi Arabia': 61,
'Jordan': 64, 'Cabo Verde': 70, 'Cape Verde': 70, 'Jamaica': 69, 'Curaçao': 82,
'Curacao': 82, 'New Zealand': 86
}
# =======================================================
# 3. PREDICTION FUNCTION
# =======================================================
def predict_match(team1, team2):
t1 = team1.strip()
t2 = team2.strip()
# Get rankings (default to 45 if a team isn't listed)
h_rank = rankings.get(t1, 45)
a_rank = rankings.get(t2, 45)
# Check if home team is one of the 2026 North American tournament hosts
is_host = 1 if t1 in ['USA', 'Mexico', 'Canada', 'United States'] else 0
# Normalized tournament baseline anchors for points-per-game form
h_ppg, a_ppg = 2.0, 1.8
# Build feature dataframe
match_input = pd.DataFrame([{
'home_rank': h_rank,
'away_rank': a_rank,
'home_ppg': h_ppg,
'away_ppg': a_ppg,
'is_host': is_host,
'rank_gap': a_rank - h_rank,
'form_gap': h_ppg - a_ppg
}])
# Run prediction
prob = model.predict_proba(match_input[features])[0]
print(f"Goal26 Prediction: {t1} vs {t2}")
print(f"----------------------------------")
print(f"{t1} Win: {prob[2] * 100:.2f}%")
print(f"Draw: {prob[1] * 100:.2f}%")
print(f"{t2} Win: {prob[0] * 100:.2f}%")
After pasting the code, click the Play button (▶️) next to the cell to run it. You should see a confirmation message print out: "Goal26 Inference Pipeline Loaded Successfully!".
Step 4: Pick Your Teams!
Now for the fun part! You can choose any two teams from our list to simulate a matchup. Here are the pool of teams our model recognizes:
'Algeria', 'Argentina', 'Australia', 'Austria', 'Belgium', 'Brazil', 'Cabo Verde', 'Canada', 'Cape Verde', 'Colombia', 'Croatia', 'Curaçao', "Côte d'Ivoire", 'Denmark', 'Ecuador', 'Egypt', 'England', 'France', 'Germany', 'Haiti', 'Iran', 'IR Iran', 'Italy', 'Ivory Coast', 'Jamaica', 'Japan', 'Jordan', 'Korea Republic', 'Mexico', 'Morocco', 'Netherlands', 'New Zealand', 'Nigeria', 'Norway', 'Panama', 'Paraguay', 'Poland', 'Portugal', 'Qatar', 'Saudi Arabia', 'Scotland', 'Senegal', 'South Africa', 'South Korea', 'Spain', 'Sweden', 'Switzerland', 'Tunisia', 'Turkiye', 'Türkiye', 'Ukraine', 'United States', 'Uruguay', 'USA', 'Uzbekistan', 'Wales'
To make a prediction, you'll use the predict_match function. You need to provide the names of the two teams exactly as written above. For example, to predict a match between Argentina and Portugal, type this snippet into a new, empty code cell:
predict_match("Argentina", "Portugal")
Step 5: Run Your Prediction!
Once you've typed in your chosen teams, click the Play button (▶️) next to that specific cell. The output window will break down the exact mathematical probability for a home team win, an away team win, or a tactical draw!
Try running it multiple times using your favorite upcoming world tournament clean-sheets or rivalries.