Tools for extracting, predicting, and optimizing Fantasy Premier League (FPL) squads using machine learning. Includes dynamic formation selection, bench output, and full JSON export for frontend use.
- Data Extraction & Feature Engineering: Reshapes and engineers FPL player data for ML prediction.
- ML Prediction: Uses Ridge and XGBoost (Optuna tuning) to predict next gameweek points for each player.
- Squad Optimization: Selects the optimal 15-player squad, starting XI, captain, vice-captain, and bench under FPL rules and budget constraints.
- Dynamic Formations: Automatically selects the best formation (or user-specified) for the starting XI.
- Bench Output: Clearly separates starting XI and bench in both console and JSON output.
- JSON Export: Outputs full squad, starting XI, bench, captain, vice-captain, and formation to
optimal_squad.json
for frontend integration.
Clone the repository and install dependencies:
git clone https://github.com/elxecutor/fpl-squad.git
cd fpl-squad
pip install -r requirements.txt
- Extract FPL player data:
This will fetch and flatten FPL player data from the API, saving it to
python export.py
players.csv
. - Run the full pipeline:
This will reshape data, engineer features, and output
python mvp_pipeline.py
players_timeseries.csv
. - Train the model and predict points:
This will train ML models and output predictions to
python train_model.py
predicted_next_gw.csv
. - Optimize squad selection:
This will output the optimal squad, starting XI (sorted by position), bench, captain, vice-captain, and formation in both console and
python squad_optimizer.py # Or specify a formation: python squad_optimizer.py 3-5-2
optimal_squad.json
.
export.py
: Extracts and flattens FPL player data from the API toplayers.csv
.mvp_pipeline.py
: Reshapes and engineers features for ML prediction, outputsplayers_timeseries.csv
.train_model.py
: Trains ML models and outputs predicted points topredicted_next_gw.csv
.squad_optimizer.py
: Loads predictions, optimizes squad selection, outputs starting XI, bench, captain, vice-captain, and formation in both console andoptimal_squad.json
.players.csv
: Output player data for ML and optimization.players_timeseries.csv
: Feature-engineered player data for ML.predicted_next_gw.csv
: Output predicted points for each player.optimal_squad.json
: Full squad, starting XI, bench, captain, vice-captain, and formation for frontend use.requirements.txt
: Python dependencies.
We welcome contributions! Please see our Contributing Guidelines and Code of Conduct for details.
This project is licensed under the MIT License.
For questions or support, please open an issue or contact the maintainer via X.