Predict league tables, knockout tournament outcomes, and championship probabilities using Machine Learning and Monte Carlo Simulation.
| Module | Capability |
|---|---|
| League Predictor | Predicts next season's points, positions & champion probabilities |
| Knockout Predictor | Predicts individual match outcomes using ELO + ML |
| Tournament Simulator | 10,000+ Monte Carlo simulations for full bracket |
| Analytics Dashboard | Strength rankings, historical trends, ELO ratings |
FinalWhistle_AI/
โ
โโโ app.py # Streamlit dashboard (main entry point)
โโโ train_league_model.py # League regression training pipeline
โโโ train_knockout_model.py # Knockout classification training pipeline
โโโ tournament_simulator.py # Monte Carlo bracket simulator
โโโ elo_rating.py # ELO rating system
โโโ utils.py # Shared utilities, feature engineering, charts
โ
โโโ data/
โ โโโ sample_league.csv # 5 Premier League seasons (2019โ2023)
โ โโโ sample_knockout.csv # UEFA CL, IPL, World Cup knockout data
โ
โโโ models/ # Saved trained models (auto-created)
โ โโโ league_model.pkl
โ โโโ knockout_model.pkl
โ
โโโ notebooks/ # Jupyter exploration notebooks
โโโ requirements.txt
โโโ README.md
pip install -r requirements.txtNote: On Windows, XGBoost installs cleanly via pip. No CMake/MSVC required.
streamlit run app.pyOpen http://localhost:8501 in your browser.
# League model
python train_league_model.py --data data/sample_league.csv
# Knockout model
python train_knockout_model.py --data data/sample_knockout.csv| Column | Aliases | Required |
|---|---|---|
season |
year |
โ |
team |
team_name, club, squad |
โ |
played |
matches_played, mp |
โ |
wins |
w, won |
โ |
draws |
d, drawn |
โ |
losses |
l, lost |
โ |
goals_scored |
gf, goals_for, runs_scored |
โ |
goals_conceded |
ga, goals_against |
โ |
goal_difference |
gd |
โ |
points |
pts |
โ |
position |
pos, rank |
Optional |
| Column | Aliases | Required |
|---|---|---|
team_a |
home_team, team1 |
โ |
team_b |
away_team, team2 |
โ |
winner |
match_winner, result |
โ |
rating_a |
elo_a, strength_a |
Optional |
rating_b |
elo_b, strength_b |
Optional |
h2h |
head_to_head |
Optional |
form_a |
recent_form_a |
Optional |
form_b |
recent_form_b |
Optional |
โก Column aliases are auto-detected. The system normalises common naming variants automatically.
- Random Forest Regressor โ ensemble tree method
- XGBoost Regressor โ gradient boosting
- Ridge Regression โ regularised linear baseline
Selection criterion: lowest cross-validated RMSE (5-fold CV)
- Random Forest Classifier
- XGBoost Classifier
- Logistic Regression
Selection criterion: highest cross-validated F1 score
- Dynamic K-factor (scales with margin of victory)
- Home advantage adjustment (+100 ELO points default)
- Snapshot-based: ratings captured before each match to prevent data leakage
Weighted composite score:
Strength = 0.40 ร Win Rate + 0.30 ร Goal Difference (normalised) + 0.30 ร PPG
from tournament_simulator import simulate_tournament
result = simulate_tournament(
teams=["Team A", "Team B", "Team C", "Team D"],
model=model, scaler=scaler,
feature_cols=feature_cols,
elo_system=elo_system,
n_simulations=10_000,
)
print(result["champion_probs"])FinalWhistle AI is sport-agnostic. The same system works for:
- โฝ Football / Soccer (Premier League, Champions League, World Cup)
- ๐ Cricket (IPL, T20 World Cup)
- ๐ฎ Esports (any structured league/tournament format)
- ๐ Basketball, ๐ American Football, ๐พ Tennis, ๐ Ice Hockey
Just provide CSV data in the expected format.
streamlit run app.pyFROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]docker build -t finalwhistle-ai .
docker run -p 8501:8501 finalwhistle-ai- Push to a GitHub repository
- Go to share.streamlit.io
- Connect your repo โ set main file as
app.py - Click Deploy
streamlit==1.32.0
pandas==2.2.1
numpy==1.26.4
scikit-learn==1.4.1
xgboost==2.0.3
matplotlib==3.8.3
plotly==5.20.0
joblib==1.3.2
scipy==1.12.0
seaborn==0.13.2
| File | Content |
|---|---|
data/sample_league.csv |
Premier League 2019โ2023 (5 seasons, 20 teams each) |
data/sample_knockout.csv |
UEFA Champions League, IPL, FIFA World Cup knockout rounds |
MIT License โ free to use, modify, and distribute.
Built with โค๏ธ ยท FinalWhistle AI ยท Universal Tournament Prediction System