Harnessing the power of linear programming to optimise your team selection, captain choice and transfers!
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Winning your fantasy football league can be a challenging and sometimes frustrating journey—but when you get it right, it’s incredibly rewarding. The path to victory often requires nailing multiple decisions, consistently. The key elements? Your initial team selection, weekly captain choice, and timely transfers. Yet, how often do we rely purely on instinct for these decisions? Why guess when we have a wealth of data at our fingertips?
This project leverages that data with PuLP, an open-source linear programming package in Python, to maximize your Fantasy Premier League team's expected points. By setting up constraints and objectives, the algorithm optimizes your lineup, captain, and transfers for each gameweek. Say goodbye to blind guessing and hello to data-driven success!
To get started with the optimiser, follow these steps to set up your development environment:
1. Clone the Repository
First, clone the repository to your local machine using Git:
git clone https://github.com/dannybozbay/FPL-Optimization.git
2. Navigate to the Project Directory
Change to the project directory:
cd FPL-Optimization
3. Create a Python Virtual Environment
It's recommended to use a virtual environment to manage dependencies. Create a virtual environment with venv:
python3 -m venv venv
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On macOS/Linux:
source venv/bin/activate
4. Install Dependencies
Install the required packages listed in requirements.txt:
pip install -r requirements.txt
5. Download Points Projection Data
Download the latest points projection from FPLForm and save it inside data/external
with the name fpl-form-predicted-points.csv
. Be sure to set the upper range of gameweeks to GW3 and select With Extra Columns before generating the CSV file.
6. Start Using the Project
You are now ready to use the optimiser. Follow the documentation and examples provided in the repository to get started.
After installing the optimiser, you can run it by following these steps:
-
Set your FPL Team ID (
team_id
) and the number of gameweeks you wish to optimise for (horizon
) in thesettings.json
file and save it. -
Run the script
run_optimiser.py
Running the optimiser will provide the following:
-
CSV table located under
data/results
with information about your optimal lineup, captain and transfers (both in and out) for each gameweek. -
TXT file located under
reports
containing a summary of actions for each gameweek, including the teams total expected points, its cost, its captain and its transfers. -
Solved LP model located under
models
.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Email: [email protected]
A special thanks to Sertalpbila for inspiring this project with his own work and for providing invaluable video tutorials on how to approach the problem. If you're looking to tackle this challenge yourself, I highly recommend checking them out!