Skip to main content

Genetic algorithm library to generate fantasy basketball lineups

Project description

fantasy-ga

fantasy-ga is a Python module and a command line tool that uses genetic algorithm to automate the generation of fantasy sports linesups. Currently supports DraftKings basketball rules.

Installation

  • Dependency
    • numpy
pip install fantasy-ga

Usage

Export a csv file from your daily fantasy basketball platform for a given contest, and read the file with fantasy_ga.read_csv. Currently DraftKings is supported.

Alternatively, you can provide a numpy.array where the columns correspond to player ID, salary, fantasy points (FPTS) and position information i.e. id,salary,fpts,PG,SG,SF,PF,C,G,F,UTIL.

Python

import numpy as np
from fantasy_ga import LineupGenerator, read_csv

model = LineupGenerator(m, n_pop, n_gen, n_breed, n_mutate, n_compound)
lineups, scores = model.fit()
optimal_lineups, top_n_scores = model.get_top_n_lineups(1)

# load data from DraftKings salary csv
id_to_name, id_to_salary, m = read_csv("examples/DraftKings/DKSalaries.csv", site="DraftKings")

# initial population of random lineups
n_pop = 1000
# number of evolutions to itererate breeding and mutation for
n_gen = 16
# number of children lineups to choose from two best lineups
n_breed = 30
# number of random mutations for each evolution
n_mutate = 30
# number of compound evolutions with additional random lineups
n_compound = 5

model = LineupGenerator(m, n_pop, n_gen, n_breed, n_mutate, n_compound)
model.fit()
optimal_lineups, top_n_scores = model.get_top_n_lineups(1)

print(
    f"Players: {[id_to_name[id] for id in optimal_lineups[0]]}\nSalary Total: {sum([id_to_salary[id] for id in optimal_lineups[0]])}\nExpected FPTS: {top_n_scores[0]}"
)

CLI

As a Python module

$ python -m fantasy_ga --filepath=examples/DraftKings/DKSalaries.csv --site=DraftKings --n_pop=100 --n_gen=5 --n_breed=100 --n_mutate=100 --n_compound=10 --top_n_lineups=1

or a CLI command

$ fantasy-ga --filepath=examples/DraftKings/DKSalaries.csv --site=DraftKings --n_pop=100 --n_gen=5 --n_breed=100 --n_mutate=100 --n_compound=10 --top_n_lineups=1  

which generates

Generated Top 1 lineups

Players: ['Russell Westbrook', 'Bruce Brown', 'Michael Porter Jr.', 'Jerami Grant', 'Mason Plumlee', 'Paul George', 'Aaron Gordon', 'Marcus Morris Sr.']
Salary Total: 49100
Expected FPTS: 254.11

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fantasy-ga-0.2.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fantasy_ga-0.2.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file fantasy-ga-0.2.0.tar.gz.

File metadata

  • Download URL: fantasy-ga-0.2.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for fantasy-ga-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6ccd957f6edd7a874d3cce4f63d8409cf35d86e789fa96183c5a5b78663b5613
MD5 d22989be4b3fb250e6a735e41cc5578b
BLAKE2b-256 fba1925bd52ac2ee6887644879deb673081ecdae906b5181f0d5ee3cd2e65c27

See more details on using hashes here.

File details

Details for the file fantasy_ga-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fantasy_ga-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for fantasy_ga-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e996a04d5bb397a7b3a11d532cd7e1b09883055a10179a01333cf925124b98ab
MD5 31c407b0f512ff5e09b0582a62b631fe
BLAKE2b-256 1c696f892621b48621beeb184e475e106c8a17b1617d2be1e47b61651da40a3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page