An end-to-end Machine Learning web application that predicts English Premier League match outcomes with high precision using advanced statistical metrics.
This project is a full-stack data science application designed to predict football match results. It automates the entire lifecycle of sports analytics:
- Data Collection: Scrapes detailed match statistics (Possession, xG, Shots) from FotMob using a custom Selenium bot.
- Data Processing: Calculates rolling form, offensive/defensive strength, and "Expected Goals" (xG) trends.
- Prediction: Uses a trained Machine Learning model to calculate probabilities for Home Win, Draw, and Away Win.
- Visualization: Presents insights via a modern, responsive Web Interface.
- Automated Data Pipeline: A robust
Seleniumscraper that handles dynamic content, cookie consents, and anti-scraping measures to build a comprehensive historical database. - Advanced Feature Engineering:
- Rolling Form: Analyzes the last 5 matches for each team to gauge current momentum.
- Tier System: Dynamically assigns team strength tiers to model "Giant vs. Underdog" scenarios.
- xG Integration: Uses Expected Goals as a primary predictive factor, superior to raw goal counts.
- RESTful API: Exposes prediction endpoints via Django REST Framework.
- Modern UI: A clean, responsive frontend built with Vanilla JS and CSS3 (Glassmorphism design), featuring dynamic team logo loading and confidence bar charts.
- Python 3.10+
- Django & Django REST Framework: For robust API architecture and ORM.
- PostgreSQL / SQLite: Data persistence.
- Scikit-Learn: For predictive modeling (Random Forest).
- Pandas & NumPy: For efficient vectorised data manipulation.
- Joblib: Model serialization.
- Selenium Webdriver: For scraping dynamic JavaScript-heavy websites (FotMob).
- Chrome/Gecko Driver: Headless browser automation.
- HTML5 / CSS3: Custom responsive design.
- JavaScript (ES6+): Async API calls and dynamic DOM manipulation.
graph LR
A[FotMob Website] -->|Selenium Scraper| B(Raw Data)
B -->|Preprocessing| C{PostgreSQL Database}
C -->|Rolling Stats| D[ML Model inference]
User -->|Select Teams| E[Web Interface]
E -->|REST API Request| F[Django Backend]
F -->|Query| D
D -->|Probabilities| F
F -->|JSON Response| E
- Python 3.8+
- Google Chrome (for the scraper)
git clone https://github.com/SirbuRobert/epl-ml-forecaster.git
cd epl-ml-forecasterpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtpython manage.py migratepython manage.py runserverVisit http://127.0.0.1:8000 to see the predictor in action.
To update the database with the latest match results:
python scraper/run_ingestion.py- Note: The scraper runs in headless mode by default. It handles cookie popups and navigates match rounds automatically.
The prediction engine uses a Random Forest Classifier approach. Key features used for training:
- Relative Form: Difference in points over the last 5 games.
- xG Differential: Difference in expected goals created vs. conceded.
- Team Tiers: Categorical ranking of team strength (1-4).
- Home Advantage: Encoded as a feature in the training set.