Code Monkey home page Code Monkey logo

fantalega_serie_ai's Introduction

FantaLega Serie AI

Framework to use Artificial Intelligence (AI) to generate optimal fantasy football teams.

Getting started | Quick run

Overview

The goal of Fanta-AI is to suggest an optimal auction strategy to maximize your chances of winning the next season of your fantasy league. The project is divided into two main parts:

  • Evaluation of all the players
  • Auction strategy

All the current data and results are based on Lega Serie A, but you are invited to modify the framework in order to accommodate your favorite international league. Let's discuss step by step Fanta-AI using as example the Serie A stagione 22/23, and good luck with your next season!

Evaluation of the players

If you are passionate for fantacalcio like me, you probably know that the winner of the fantasy league is mainly determined by luck, but in order to be a candidate for this lottery you have to build a solid team. To build an optimal team it is necessary to pick good players. The first step is then to estimate the potential of each player.

In this project there are 3 available alternatives for the player evaluation that can be selected using the --ev_type [manuale/fantagazzetta/piopy] argument, which correspond to:

  • Manual evaluation: for hardcore players that know better than anyone else, the optimal strategy is to manually rank the players. To perform this operation the user has to follow the excel table Players_evaluation/Le_mie_valutazioni.xlsx, which has the following structure:
Ruolo Nome Valutazione
[P/D/C/A] [cognome del calciatore] [da 1 a 100]
P Provedel 25
... ...
A Osimhen 95

You can edit this file and change the rank (Valutazione) as you prefer. For future seasons and different leagues, you have to update the player list and their corresponding role.

  • Fantagazzetta: you can download the list of players from fantacalcio.it. This has to be placed in Players_evaluation/Quotazioni_Fantagazzetta.xlsx. The evaluation of the players will be made according to the professional journalists of fantagazzetta.
  • Fantaciclopedia (piopy): based on piopy tool, this evaluation uses the real statistics of the last two seasons, available on fantaciclopedia. To perform this type of evaluation you have to run
python Evaluate_players.py 

Notice that the output Players_evaluation/giocatori_excel.xls is highly informative and detailed, and can serve as a valuable tool in the arsenal of the good fantallenatore. I invite you to explore its details here.

Pick the best team

After you have evaluated all the players according to your favorite metric, you have to build your team during the auction. This project is based on the following 2 assumptions to model the auction:

  • All the auctioneers (your friends in the fantalega) are decent players and their evaluation will not be much different compared to yours.
  • The auction is a classic English auction, with open ascending bids (la classica asta a chiamata)

Accepting this assumptions, we can model the fantacalcio auction as a knapsack problem which is a typical problem in combinatorial optimization.

To solve this problem, FantaAI implements a genetic algorithm that evolves to generate the best teams that you can realistically expect to build during your real auction. You can run it using

python Pick_my_team.py # --[arguments]

There are several arguments that can be set for the specific use case, and to develop your favorite strategy:

  • --crediti : initial budget for each team
  • --n[P/D/C/A] : number of players per role P/D/C/A for each team
  • --max_b_[P/D/C/A] : maximum percentage of the budget to invest in the specific role P/D/C/A
  • --t[P/D/C/A] : target of good players per role. An optimal team invest most of its budget in a few solid picks rater than spreading too much
  • --bonus_multiplier : how much to weight the top players for each role
  • --pop_size : size of the population for the genetic algorithm
  • --num_gen : number of generations of evolution
  • --mutation_rate : rate of mutations for the genetic algorithm
  • --swap_mutation_rate : rate of recombinations for the genetic algorithm

Getting started

  1. Clone this repository
git clone https://github.com/SCiarella/FantaLega_Serie_AI.git
  1. Setup virtual environment
cd FantaLega_Serie_AI/
python -m venv fantaAI-venv
source ./fantaAI-venv/bin/activate
  1. Install requirements
pip install -r requirements.txt

Quick run

  1. (Optional) if you want to use piopy evaluation method
python Evaluate_players.py 
  1. Pick an optimal team
python Pick_my_team.py

Acknowledgements

Fanta-AI implements as a possible model for player evaluation the project fantacalcio-py developed by piopy and based on the data from Fantaciclopedia

fantalega_serie_ai's People

Contributors

sciarella avatar

Stargazers

Johon Li Tuobang 李拓邦 avatar  avatar ze avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.