DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
409 stars 155 forks source link

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

Open chanzer0 opened 1 year ago

chanzer0 commented 1 year ago

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 commented 1 year ago

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

Denwen12 commented 1 year ago

Do they hace multiple position as in Pf/c

On Wed, Jan 11, 2023, 8:48 PM jbunting7711 @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/400#issuecomment-1379707639, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7QFF6JUQRCWAOPUELLWR5PIHANCNFSM6AAAAAATXR3Y3E . You are receiving this because you are subscribed to this thread.Message ID: @.***>