A comprehensive Fantasy Premier League (FPL) optimization tool that uses machine learning and linear programming to predict player performance and generate optimal team selections.
This project combines historical FPL data analysis, XGBoost machine learning models, and PuLP optimization to:
- Predict player performance for upcoming gameweeks
- Generate optimal team selections for single and multi-period strategies
- Scrape expert recommendations from Fantasy Football Scout
- Optimize transfers and captaincy decisions
- Machine Learning Predictions: XGBoost model trained on historical player performance data
- Team Optimization: Single and multi-period FPL team optimization using linear programming
- Expert Integration: Fantasy Football Scout scraper for incorporating expert recommendations
- Historical Data: Comprehensive dataset covering 2023-2025 seasons
- Transfer Planning: Multi-gameweek transfer optimization
model.py
- XGBoost model training and prediction generationfpl_optimizer.py
- Basic FPL optimization logicfpl_optimizer_single_period.py
- Single gameweek optimizationfpl_optimizer_multi_period.py
- Multi-gameweek optimization with transfersffs_scraper.py
- Fantasy Football Scout recommendations scraper (standalone)data_download.py
- Combined FPL API data collection and FFS scraping scriptdata_2023/
,data_2024/
,data_2025/
- Historical and current season data
- Clone the repository:
git clone [repository-url]
cd Fantasy_Football_v2
- Install dependencies:
pip install -r requirements.txt
Or using uv:
uv pip install -r requirements.txt
python model.py
# Single gameweek optimization
python fpl_optimizer_single_period.py
# Multi-gameweek optimization with transfers
python fpl_optimizer_multi_period.py
python ffs_scraper.py
python data_download.py
This command downloads both FPL API data and Fantasy Football Scout recommendations in a single run.
- FPL API: Official Fantasy Premier League API for player stats and fixtures
- Fantasy Football Scout: Expert recommendations and insights
- Historical Data: Multi-season player performance and team data
The XGBoost model uses features including:
- Player historical performance
- Fixture difficulty ratings
- Team form and statistics
- Previous season performance
Optimized teams and predictions are saved to:
data_2025/predictions/
- Model predictions and optimal teamsdata_2025/ffs_recommendations/
- Expert recommendations
Key libraries used:
xgboost
- Machine learning modelpulp
- Linear programming optimizationpandas
- Data manipulationnumpy
- Numerical computingscikit-learn
- Model evaluationbeautifulsoup4
- Web scrapingrequests
- API calls
- Build XGBoost model based on previous years
- Think about pulp scoring: captain, bench and transfers
- Dealing with changing team ids (relegations)
- Player transfers
- Free to change captain
- How many bench positions to actually use