← BACK

AI-Football-Match-Prediction-Betting-Analytics-Engine

Python ⭐ 1

AI Football Match Prediction & Betting Analytics Engine

This is a personal project where I built a football match prediction and value betting assistant from scratch.

🔍 What this project does

  • Collects match data for top European leagues using the football-data.org API.
  • Builds a training dataset with team form, goals, home/away strength and simple xG-style stats.
  • Trains an XGBoost model to predict home win / draw / away win.
  • Calibrates the predicted probabilities using Platt scaling and isotonic regression.
  • Compares model probabilities with bookmaker odds to detect value bets.
  • Uses the Kelly Criterion (with a safe fraction) to suggest stake size.
  • Supports live mode: you can enter current minute + score, and the model adjusts win/draw/lose probabilities.

🧠 Tech stack

  • Python 3
  • Pandas, NumPy
  • scikit-learn, XGBoost
  • Requests (for HTTP APIs)
  • Git & GitHub

📂 Main files

  • update_results_all_leagues.py – downloads & updates historical match results.
  • build_ml_dataset_v3.py – builds the ML dataset (ml_dataset_v3.csv) from the results.
  • train_ml_xgb_v3.py – trains the base XGBoost classifier.
  • train_ml_xgb_calibrated.py – calibrates the probabilities and saves football_ml_model.pkl.
  • model.py – core prediction logic (features, probabilities, live adjustment, betting logic).
  • manual_predict.py – command-line interface: enter teams, date, status, odds → get prediction & suggested bet.

▶ How to run (locally)

# 1. Install dependencies
pip install -r requirements.txt   # (or manually install pandas, numpy, scikit-learn, xgboost, requests)

# 2. Set your API key
# Edit fd_api.py (or api_handler.py) and put your football-data.org API key there.

# 3. Update / rebuild data and model (optional, only when you want to refresh)
python update_results_all_leagues.py
python build_ml_dataset_v3.py
python train_ml_xgb_v3.py
python train_ml_xgb_calibrated.py

# 4. Use the CLI prediction tool
python manual_predict.py