Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lineup generator produces an Infeasible lineup result with custom projections #400

Open
chanzer0 opened this issue Jan 11, 2023 · 2 comments

Comments

@chanzer0
Copy link

chanzer0 commented Jan 11, 2023

I'm digging into the code a bit, and trying to optimize using local projections:

from pydfs_lineup_optimizer import get_optimizer, Site, Sport, Player
import pandas as pd


player_ids = pd.read_csv('../dk_data/player_ids.csv')
projections = pd.read_csv('../dk_data/projections.csv')
projections = projections[projections['Fpts'] >= 10]

optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL)


def row_to_player(row):
    player_pos = [pos for pos in player_ids.loc[player_ids['Name'] ==
                                                row['Name']]['Roster Position'].item().split('/')]
    player_pos.remove('UTIL')
    player = Player(
        player_id=player_ids.loc[player_ids['Name']
                                 == row['Name']]['ID'].item(),
        first_name=row['Name'].split(' ')[0],
        last_name=row['Name'].split(' ')[1],
        positions=player_pos, # player_pos = ['PG', 'SG', 'G'] for example
        team=row['Team'],
        salary=float(row['Salary'].replace(',', '')),
        fppg=row['Fpts'],
    )
    return player


players = projections.apply(row_to_player, axis=1)

optimizer.player_pool.load_players(players)
lineups = list(optimizer.optimize(10))
optimizer.export('result.csv')

And I'm met with the following error:

Traceback (most recent call last):
  File "D:\Repositories\NBA-DFS-Tools\src\optimizer.py", line 37, in <module>
    lineups = list(optimizer.optimize(10))
  File "C:\Users\seans\AppData\Roaming\Python\Python310\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 463, in optimize
    lineup = self._build_lineup(lineup_players, context)
  File "C:\Users\seans\AppData\Roaming\Python\Python310\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 584, in _build_lineup
    players_with_positions = link_players_with_positions(
  File "C:\Users\seans\AppData\Roaming\Python\Python310\site-packages\pydfs_lineup_optimizer\utils.py", line 113, in link_players_with_positions
    raise LineupOptimizerException('Unable to build lineup')
pydfs_lineup_optimizer.exceptions.LineupOptimizerException: Unable to build lineu

I've looked into the file and added a print statement on line 568 in lineup_optimizer.py right at the initial part of the def _build_lineup() function. This outputs a lineup result:
[Dario Saric C/F/PF (PHX), Duane Washington G/PG/SG (PHX), Hamidou Diallo F/G/SF/SG (DET), Jimmy Butler F/PF (MIA), Jock Landale C (PHX), Joel Embiid C (PHI), Luka Doncic G/PG (DAL), Orlando Robinson C (MIA)]
Obviously this result is infeasible due to the fact that htere are 3 Center-only positions (Landale, Embiid, Robinson), and thus _build_lineup() is unable to fit them all in a normal roster and raises the Exception.

What could be causing this issue that this lineup was produced by the optimizer? Is my input data wrong? Are the opto rules wrong?

here are the files im using: https://gist.github.com/chanzer0/f787c126e42c10d094b94d30863797a4

@jbunting7711
Copy link

jbunting7711 commented Jan 12, 2023

I've noticed this, too. It's always a lineup that's generated with 3 center only players...

@Denwen12
Copy link

Denwen12 commented Jan 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants