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.
- Transfer Suggestions: Analyzes your current squad and recommends transfers to maximize predicted points (accounting for transfer costs).
- 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.jsonandupdated_squad.jsonfor 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 and suggest transfers:
This will load your current squad from
python squad_optimizer.py # Or specify a formation: python squad_optimizer.py 3-5-2data/updated_squad.json, check player availability, suggest transfers to maximize predicted points (accounting for 4-pt transfer hits), and output the updated squad, starting XI (sorted by position), bench, captain, vice-captain, and formation in both console andupdated_squad.json. If no current squad exists, it optimizes a new squad and saves tooptimal_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 new squad selection or analyzes current squad fromdata/updated_squad.jsonfor transfer suggestions (accounting for 4-pt hits), outputs starting XI, bench, captain, vice-captain, and formation in both console and JSON files.transfer_optimizer.py: Analyzes a current squad (entered interactively) and suggests the best transfer to improve predicted points, outputs to console anddata/updated_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 optimized squad, starting XI, bench, captain, vice-captain, and formation for frontend use (when no current squad is provided).updated_squad.json: Updated squad after applying transfer recommendations, including availability checks, transfer summary, and totals.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.