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

# 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.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fantasy-ga-0.2.1.tar.gz
  • Upload date:
  • Size: 15.0 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.1.tar.gz
Algorithm Hash digest
SHA256 4ef9e33386f78352bc14dcced250af0eb95336459d7d3cd662dcc87be2602ba0
MD5 6334998e91dd08ca5b22416e54711b3a
BLAKE2b-256 fa0e0e05078b346febc00a017290d6c6a260ca42017744746304ef51613ea5f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fantasy_ga-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af4cf1871130088cd45adbf829a7e50a2d50a273d981a0c5f88a5536f214f6b1
MD5 59f518bbece2545e609eb0b7de22ff2a
BLAKE2b-256 2f1a4fe02a286521c21ad1acebaad0e85d9db9653c2f77f172e404bae5b889d8

See more details on using hashes here.

Supported by

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