• Stars
    star
    254
  • Rank 155,365 (Top 4 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 10 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Machine learning Fantasy Premier League team

AIrsenal

Build Status

AIrsenal is a package for using Machine learning to pick a Fantasy Premier League team.

For some background information and details see https://www.turing.ac.uk/research/research-programmes/research-engineering/programme-articles/airsenal.

We welcome contributions and comments - if you'd like to join the AIrsenal community please refer to our contribution guidelines

NEW (1st September 2022)

Changes merged from develop branch - See here for new instructions on setting your Team ID, Username etc.

Mini-league for 2022/23 season

We have made a mini-league "Prem-AI League" for players using this software. To join, login to the FPL website, and navigate to the page to join a league: https://fantasy.premierleague.com/leagues/create-join then click "join a league or cup". The code to join is: 8wec9c. Hope to see your AI team there! :)

Our own AIrsenal team's id for the 2022/23 season is 2779516.

Installation

We recommend running AIrsenal in a conda environment. For instructions on how to install conda go to this link: https://docs.anaconda.com/anaconda/install/, or the more lightweight MiniConda: https://docs.conda.io/en/latest/miniconda.html.

With conda installed, run these commands in a terminal to create a new conda environment and download and install AIrsenal:

Linux and macOS

git clone https://github.com/alan-turing-institute/AIrsenal.git
cd AIrsenal
conda env create
conda activate airsenalenv

Windows

The best ways to run AIrsenal on Windows are either to use Windows Subsystem for Linux (WSL), which allows you to run AIrsenal in a Linux environment on your Windows system, or Docker (see below).

After installing WSL, if you'd like to use AIrsenal with conda run the following commands to install it from your WSL terminal (following the Linux instructions here):

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

You can then follow the installation instructions for Linux and macOS above (or the instructions for without conda below).

You're free to try installing and using AIrsenal in Windows itself, but so far we haven't got it working. The main difficulties are with installing jax and some database/pickling errors (e.g. #165). If you do get it working we'd love to hear from you!

Use AIrsenal without conda

To use AIrsenal without conda:

git clone https://github.com/alan-turing-institute/AIrsenal.git
cd AIrsenal
pip install pygmo  # Linux only
pip install .

AIrsenal has an optional optimisation algorithm using the PyGMO package, which is only pip-installable on Linux (either use conda or don't install pygmo on other platforms). However, we have also occasionally seen errors when using conda (e.g. #81)

Docker

Build the docker-image:

docker build -t airsenal .

Create a volume for data persistance:

docker volume create airsenal_data

Run commands with your configuration as environment variables, eg:

docker run -it --rm -v airsenal_data:/tmp/ -e "FPL_TEAM_ID=<your_id>" -e "AIRSENAL_HOME=/tmp" airsenal [airsenal_run_pipeline]

airsenal_run_pipeline is the default command.

Optional dependencies

AIrsenal has optional dependencies for plotting, running notebooks, and an in development AIrsenal API. To install them run:

pip install ".[api,notebook,plot]"

Configuration

Once you've installed the module, you will need to set the following parameters:

Required:

  1. FPL_TEAM_ID: the team ID for your FPL side.

Optional:

  1. FPL_LOGIN: your FPL login, usually email (this is only required to get FPL league standings, or automating transfers via the API).

  2. FPL_PASSWORD: your FPL password (this is only required to get FPL league standings, or automating transfers via the API).

  3. FPL_LEAGUE_ID: a league ID for FPL (this is only required for plotting FPL league standings).

  4. AIRSENAL_DB_FILE: Local path to where you would like to store the AIrsenal sqlite3 database. If not set AIRSENAL_HOME/data.db will be used by default.

The values for these should be defined either in environment variables with the names given above, or as files in AIRSENAL_HOME (a directory AIrsenal creates on your system to save config files and the database).

To view the location of AIRSENAL_HOME and the current values of all set AIrsenal environment variables run:

airsenal_env get

Use airsenal_env set to set values and store them for future use. For example:

airsenal_env set -k FPL_TEAM_ID -v 123456

See airsenal_env --help for other options.

Getting Started

If you installed AIrsenal with conda, you should always make sure the airsenalenv virtual environment is activated before running AIrsenal commands. To activate the environment use:

conda activate airsenalenv

Note: Most the commands below can be run with the --help flag to see additional options and information.

1. Creating the database

Once the module has been installed and your team ID configured, run the following command to create the AIrsenal database:

airsenal_setup_initial_db

This will fill the database with data from the last 3 seasons, as well as all available fixtures and results for the current season. On Linux/Mac you should get a file /tmp/data.db containing the database (on Windows you will get a data.db file in a the temporary directory returned by the python tempfile module on your system).

You can run sanity checks on the data using the following command:

airsenal_check_data

2. Updating and Running Predictions

To stay up to date in the future, you will need to fill three tables: match, player_score, and transaction with more recent data, using the command

airsenal_update_db

The next step is to use the team- and player-level Stan models to predict the expected points for all players for the next fixtures. This is done using the command

airsenal_run_prediction --weeks_ahead 3

(we normally look 3 weeks ahead, as this is an achievable horizon to run the optimization over, but also because things like form and injuries can change a lot in 3 weeks!)

Predicted points must be generated before running the transfer or squad optimization (see below).

3. Transfer or Squad Optimization

Finally, we need to run the optimizer to pick the best transfer strategy over the next weeks (and hence the best team for the next week).

airsenal_run_optimization --weeks_ahead 3

This will take a while, but should eventually provide a printout of the optimal transfer strategy, in addition to the teamsheet for the next match (including who to make captain, and the order of the substitutes). You can also optimise chip usage with the arguments --wildcard_week <GW>, --free_hit_week <GW>, --triple_captain_week <GW> and --bench_boost_week <GW>, replacing <GW> with the gameweek you want to play the chip (or use 0 to try playing the chip in all gameweeks).

Note that airsenal_run_optimization should only be used for transfer suggestions after the season has started. If it's before the season has started and you want to generate a full squad for gameweek one you should instead use:

airsenal_make_squad --num_gameweeks 3

4. Apply Transfers and Lineup

To apply the transfers recommended by AIrsenal to your team on the FPL website run airsenal_make_transfers. This can't be undone! You can also use airsenal_set_lineup to set your starting lineup, captaincy choices, and substitute order to AIrsenal's recommendation (without making any transfers). Note that you must have created the FPL_LOGIN and FPL_PASSWORD files for these to work (as described in the "Configuration" section above).

Also note that this command can't currently apply chips such as "free hit" or "wildcard", even if those were specified in the airsenal_run_optimization step. If you do want to use this command to apply the transfers anyway, you can play the chip at any time before the gameweek deadline via the FPL website.

Run the Full AIrsenal Pipeline

Instead of running the commands above individually you can use:

airsenal_run_pipeline

This will update the database and then run the points predictions and transfer optimization. Add --help to see the available options.

Issues and New Features

AIrsenal is regularly developed to fix bugs and add new features. If you have any problems during installation or usage please let us know by creating an issue (or have a look through existing issues to see if it's something we're already working on).

You may also like to try the development version of AIrsenal, which has the latest fixes and features. To do this checkout the develop branch of the repo and reinstall:

git pull
git checkout develop
pip install --force-reinstall .

Contributing

We welcome all types of contribution to AIrsenal, for example questions, documentation, bug fixes, new features and more. Please see our contributing guidelines. If you're contributing for the first time but not sure what to do a good place to start may be to look at our current issues, particularly any with the "Good first issue" tag. Also feel free to just say hello!

Development

If you're developing AIrsenal you may find it helpful to install it in editable mode:

pip install -e .

We're in the process of migrating to Poetry, but as PyGMO is not available on PyPI on all platforms this is a work on progress. However, you can set up a development environment without PyGMO by running poetry install and then poetry shell to enter the environment.

We also have a pre-commit config to run the code quality tools we use (flake8, isort, and black) automatically when making commits. If you're using poetry it will be installed as a dev dependency, otherwise run pip install pre-commit. Then to setup the commit hooks:

pre-commit install --install-hooks

More Repositories

1

MLJ.jl

A Julia machine learning framework
Julia
1,725
star
2

the-turing-way

Host repository for The Turing Way: a how to guide for reproducible data science
TeX
1,635
star
3

CleverCSV

CleverCSV is a Python package for handling messy CSV files. It provides a drop-in replacement for the builtin CSV module with improved dialect detection, and comes with a handy command line application for working with CSV files.
Python
1,145
star
4

distinctipy

A lightweight package for generating visually distinct colours.
Python
228
star
5

rse-course

Materials for The Alan Turing Institute's Research Software Engineering course
Jupyter Notebook
220
star
6

ReadabiliPy

A simple HTML content extractor in Python. Can be run as a wrapper for Mozilla's Readability.js package or in pure-python mode.
HTML
178
star
7

TCPD

The Turing Change Point Dataset - A collection of time series for the evaluation and development of change point detection algorithms
Python
116
star
8

TCPDBench

The Turing Change Point Detection Benchmark: An Extensive Benchmark Evaluation of Change Point Detection Algorithms on real-world data
114
star
9

scivision

scivision: a framework for scientific image analysis
JavaScript
91
star
10

environmental-ds-book

A computational notebook community for open environmental data science 🌎
TeX
87
star
11

WorldCupPrediction

Predicting results for the FIFA Men's 2022 World Cup and the FIFA Women's 2023 World Cup.
Jupyter Notebook
69
star
12

deepsensor

A Python package for tackling diverse environmental prediction tasks with NPs.
Python
64
star
13

SHEEP

SHEEP is a Homomorphic Encryption Evaluation Platform
C++
47
star
14

mogp-emulator

Package for fitting Gaussian Process Emulators to multiple output computer simulation results.
Python
45
star
15

TuringDataStories

TuringDataStories: An open community creating “Data Stories”: A mix of open data, code, narrative 💬, visuals 📊📈 and knowledge 🧠 to help understand the world around us.
Jupyter Notebook
40
star
16

SemAIDA

Semantic Technologies for the AIDA project
Python
37
star
17

data-safe-haven

PowerShell
36
star
18

mathematics-of-ml-course

Jupyter Notebook
34
star
19

AutSPACEs

Code respository for AutSPACEs: the Autistica/Turing citizen science platform
Python
34
star
20

grace

Graph Representation Analysis for Connected Embeddings
Jupyter Notebook
34
star
21

PDSampler.jl

Piecewise Deterministic Sampler library (Bouncy particle sampler, Zig Zag sampler, ...)
Julia
33
star
22

rds-course

Materials for Turing's Research Data Science course
Jupyter Notebook
31
star
23

ds-ai-educators-programme

The Data Science and AI Educators' Programme
31
star
24

tapas

Python
30
star
25

ptype

Probabilistic type inference
Jupyter Notebook
29
star
26

bocpdms

Python
29
star
27

AutisticaCitizenScience

Project management and resource repository for the Autistica/Turing Citizen Science project
Ruby
28
star
28

TimeSeriesClassification.jl

Machine Learning with Time Series in Julia
Julia
27
star
29

xpandas

Universal 1d/2d data containers with Transformers functionality for data analysis.
Python
26
star
30

CSV_Wrangling

Repository for reproducibility of the CSV file project
TeX
26
star
31

datadiff

Datadiff is diff for data
R
25
star
32

foundation-models-reading-group

Information and materials for the Turing's Foundation Models reading group.
Jupyter Notebook
25
star
33

SigNet

A package for clustering of Signed Networks
Python
24
star
34

CROP

CROP is a Research Observation Platform
Python
24
star
35

turing-roche-partnership

23
star
36

solar-panel-detection

Solar Panel Detection (Turing Climate Action Call)
Jupyter Notebook
22
star
37

open-research-community-management

Establishing cross-community collaborations and promoting open research in data science
Jupyter Notebook
21
star
38

monitoring-ecosystem-resilience

Repository for mini-projects in the Data science for Sustainable development project
Python
21
star
39

rbocpdms

Robust bayesian online changepoint detection with model selection
Python
21
star
40

ThermodynamicAnalyticsToolkit

Sampling-based approach to analyse neural networks using TensorFlow
Python
21
star
41

signatures-psychiatry

Code from the paper "A signature-based machine learning model for bipolar disorder and borderline personality disorder".
Python
21
star
42

QUIPP-pipeline

Privacy preserving synthetic data generation workflows
Python
20
star
43

uatk-spc

Synthetic Population Catalyst
Jupyter Notebook
20
star
44

AnnotateChange

A simple flask application to collect annotations for the Turing Change Point Dataset, a benchmark dataset for change point detection algorithms
Python
19
star
45

AssurancePlatform

Project to facilitate creation of Assurance Cases
JavaScript
17
star
46

the-turing-way-book

The Turing Way: A Handbook for Reproducible Data Science
CSS
16
star
47

turing-commons

The main repository for the Turing Commons platform
HTML
16
star
48

defoe

Code to analyse books and newspapers data using Apache Spark.
Lex
16
star
49

Palaeoanalytics

Repository for the Paleoanalytics project.
Python
16
star
50

rPSMF

Code for Probabilistic Sequential Matrix Factorization
Python
15
star
51

learning-at-the-turing

The core repository for training materials at the Alan Turing Institute.
13
star
52

autoemulate

emulate simulations easily
Python
13
star
53

HDS-DiscussionGroup

Repo of the Turing's Humanities & Data Science Discussion Group
13
star
54

network-comparison

An R package implementing the NetEMD and NetDis network comparison measures
R
13
star
55

templates

Turing Beamer templates for presentations
TeX
13
star
56

bias-in-AI-course

Jupyter Notebook
12
star
57

reproducible-project-template

Template repository for setting a reproducible research project.
12
star
58

room2glo

Python
12
star
59

RSE4DataScience18

Repo containing docs and outputs from the RSE4DataScience18 meeting.
12
star
60

affinity-vae

Self-supervised method for disentanglement, clustering and classification of objects in multidimensional image data
Python
12
star
61

research-application-management

11
star
62

advent-of-code-2021

Advent of Code 2021
Racket
11
star
63

SIMple-ID

SIM-based QR-code authentication for basic and feature phones
TeX
11
star
64

notice-board

Community notice board for the Turing Institute
11
star
65

stat-fem

Python tools for solving data-constrained finite element problems
Python
11
star
66

ReproducibleResearchResources

This repository contains information to help you make your research reproducible
10
star
67

clim-recal

Open repository of methods for recalibrating & bias correcting UKCP18 climate projections data
HTML
10
star
68

python-project-template

Python
10
star
69

sqlsynthgen

Synthetic data for SQL databases
Python
10
star
70

Turing-RSS-Health-Data-Lab-Biomedical-Acoustic-Markers

Python
9
star
71

professionalising-data-science-roles

Policy Skills Award project with TPS and Skills team - Professionalising traditional and infrastructure research roles in data science
9
star
72

DTBase

A starting point from which digital twins can be developed.
Python
9
star
73

DH-RSE-Summer-School

R
9
star
74

data-training-for-bioscience

Introduction to Data Science Project Management for Project Leaders.
9
star
75

spatial-inequality

Jupyter Notebook
9
star
76

guard

Simulating Imperial Dynamics and Conflict in the Ancient World
Jupyter Notebook
8
star
77

AI-workflows

A collections of portable, real-world AI workflows for testing and benchmarking
Shell
8
star
78

netts

Toolbox for creating networks capturing semantic content of speech transcripts.
Python
8
star
79

p2lab-pokemon

A Python library for running genetic algorithms to optimize Pokemon teams!
Python
8
star
80

hub23-deploy

A repo to manage the Turing BinderHub instance
Python
8
star
81

jbc-turing-rss-nowcasting

A Bayesian model for time-series count data with weekend effects and a lagged reporting process
Jupyter Notebook
8
star
82

mousehole

Quickly deploy a flexible, collaborative environment for working with private data.
HCL
8
star
83

learn-azure

Repository for generalised learning materials on Azure
Python
8
star
84

DSSG19-HomelessLink-PUBLIC

TSQL
8
star
85

cage-challenge-2-public

Team Mindrake's hierarchical RL solution to the second CybORG CAGE challenge.
Python
8
star
86

trustchain

Trustworthy decentralised PKI
Rust
8
star
87

uicc_identity_toolbox

A framework of Java Card applets for enhancing the trustworthiness of DigitalID systems using low-cost basic and feature phone devices.
TeX
8
star
88

gnn-reading-group

Public-facing repo for organising activities+ archiving material relating to the Graph Neural Network reading group.
TypeScript
8
star
89

COVID-19_PSTC

Pandemic Symptom Tracker Calendar open code /Symptom tracker open code repository
HTML
8
star
90

Intro-to-transparent-ML-course

An Introduction to Transparent Machine Learning
Jupyter Notebook
8
star
91

branded-overleaf-template

TeX
7
star
92

alexa-room-finder

Lets you find meeting rooms through our Amazon Echo
JavaScript
7
star
93

causal-cyber-defence

This repository contains glue-code necessary to run dynamic Causal Bayesian optimisation within the Yawning Titan cyber-simulation environment.
Jupyter Notebook
7
star
94

DSSG19-Cochrane-PUBLIC

Python
7
star
95

pam-aad-oidc

PAM module connecting to AzureAD for user authentication using OpenID Connect/OAuth2.
Go
6
star
96

empiarreader

Reader for EMPIAR datasets
Python
6
star
97

DSSG

meta repository for DSSG projects
6
star
98

REG-handbook

A way of working guide for the Research Engineering Group at The Alan Turing Institute
HTML
6
star
99

reprosyn

Python
6
star
100

Data-Study-Group-

Data Study Group Organisers Hub
HTML
6
star