A sophisticated analytics tool that leverages machine learning and AI-driven insights to build your optimal Fantasy Premier League (FPL) squad.
This project goes beyond basic statistics — combining a predictive ML model, a mathematical optimizer, and qualitative AI scouting reports to give you a decisive edge in FPL team selection.
- 📊 Live Data Integration – Fetches real-time player data from the official FPL API for the most current stats.
- 🔮 Predictive Analytics – Uses a pre-trained XGBoost model to forecast expected points (xP) for every player.
- 🤖 AI Scouting Reports – Integrates with Google's Gemini API to provide insights on player form, injuries, and tactical roles.
- ⚙️ Optimal Squad Generation – Uses the PuLP optimization library to build the best 15-player squad within budget and rules.
- 📈 Fixture Difficulty Rating (FDR) – Calculates attacking & defensive strength to assess match difficulty.
- 🔧 Manual Overrides – Adjust player scores with your own scouting bias in
main.py.
graph LR
A[Live FPL API Data] --> B[Data Processing & FDR Calculation]
B --> C[XGBoost Point Prediction]
C --> D[Gemini AI Scouting]
D --> E[PuLP Squad Optimization]
E --> F[Final Team Output]
| Category | Technology |
|---|---|
| Core Language | Python 3 |
| Data Science | Pandas, NumPy, Scikit-learn |
| Machine Learning | XGBoost |
| Optimization | PuLP |
| API & Web | Requests, Google Generative AI, python-dotenv |
- Python 3.8+
- Git
- Google AI Studio API Key (for Gemini AI scouting)
# Clone the repository
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
# Create & activate a virtual environment
python -m venv venv
source venv/bin/activate # Windows: .\venv\Scripts\activate
# Install all dependencies
pip install -r requirements.txtCreate a .env file in the project root:
GEMINI_API_KEY="YOUR_API_KEY_HERE"(Optional) Customize scout_overrides and player_team_overrides in main.py to add your own bias.
python main.pyThe script outputs:
- Starting XI
- Bench
- Captain
.
├── data/
│ ├── epl_player_stats_24_25.csv
│ ├── fpl_playerstats_2023-24.csv
│ ├── fpl_playerstats_2024-25.csv
│ └── fpl_xgb_model.json
│
├── scripts/
│ ├── data_processing.py
│ ├── fixtures.py
│ ├── fpl_playerstats_2024-25.csv
│ ├── model_trainer.py
│ ├── optimized_main.py
│ ├── scout.py
│ └── scraping_script.py
│
├── .env
├── .gitattributes
├── .gitignore
├── README.md
└── requirements.txt
- Static Prediction Model – The XGBoost model does not retrain automatically during the season.
- Single Gameweek Focus – Optimizes only for the upcoming gameweek.
- Outdated Fixtures Risk –
fixtures.pymust be updated manually for each season.
- Automated weekly model retraining.
- Multi-gameweek lookahead for strategic planning.
- Weekly transfer & captaincy suggestion module.