Skip to content

Extract, predict, and optimize Fantasy Premier League squads using machine learning and mathematical optimization. Features include data extraction from FPL API, ML-based point predictions, flexible formation selection, and squad optimization under FPL rules and budget constraints.

License

Notifications You must be signed in to change notification settings

elxecutor/fpl-squad

FPL Squad Optimizer

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.

Table of Contents

Features

  • 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.

Installation

Clone the repository and install dependencies:

git clone https://github.com/elxecutor/fpl-squad.git
cd fpl-squad
pip install -r requirements.txt

Usage

  1. Extract FPL player data:
    python export.py
    This will fetch and flatten FPL player data from the API, saving it to players.csv.
  2. Run the full pipeline:
    python mvp_pipeline.py
    This will reshape data, engineer features, and output players_timeseries.csv.
  3. Train the model and predict points:
    python train_model.py
    This will train ML models and output predictions to predicted_next_gw.csv.
  4. Optimize squad selection:
    python squad_optimizer.py
    # Or specify a formation:
    python squad_optimizer.py 3-5-2
    This will output the optimal squad, starting XI (sorted by position), bench, captain, vice-captain, and formation in both console and optimal_squad.json.

File Overview

  • export.py: Extracts and flattens FPL player data from the API to players.csv.
  • mvp_pipeline.py: Reshapes and engineers features for ML prediction, outputs players_timeseries.csv.
  • train_model.py: Trains ML models and outputs predicted points to predicted_next_gw.csv.
  • squad_optimizer.py: Loads predictions, optimizes squad selection, outputs starting XI, bench, captain, vice-captain, and formation in both console and optimal_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.

Contributing

We welcome contributions! Please see our Contributing Guidelines and Code of Conduct for details.

License

This project is licensed under the MIT License.

Contact

For questions or support, please open an issue or contact the maintainer via X.

About

Extract, predict, and optimize Fantasy Premier League squads using machine learning and mathematical optimization. Features include data extraction from FPL API, ML-based point predictions, flexible formation selection, and squad optimization under FPL rules and budget constraints.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages