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

Does Anyone know is there a way? #426

Open
Milkman9691 opened this issue Apr 10, 2024 · 44 comments
Open

Does Anyone know is there a way? #426

Milkman9691 opened this issue Apr 10, 2024 · 44 comments

Comments

@Milkman9691
Copy link

@DimaKudosh is there a way to form stacks this way?

I have my roster order columns and batting orders before I run the opt but I was trying to eliminate the 7,8,9 hitters from my stack consideration but not for overall lineup consideration. If "optimizer.set_spacing_for_positions(['1B', '2B', '3B'], 3)" is used it could use a 9,1,2 wrap or 8,9,1 wrap to which i am trying to avoid. The "spacing=" argument could also give a wrap around. For MLB the 7,8,9 roster positions are pretty much useless but you will still need to be able to let them be in the selection process but wantig the core of stacks to come from the 1-6 positions. In 2023 82.7% of the top fantasy points scored came from batting positions 1-6 So far in 2024 that number is 79%. This is the importance of wanting to try to find a way.

optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_roster_order=['1', '2', '3', '4', '5','6']))
or
optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_roster_order=['1-6']))

Thx beforehand

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Thanks bunches. You are awesome for creating this btw.

@Milkman9691
Copy link
Author


TypeError Traceback (most recent call last)
Cell In[58], line 1
----> 1 optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_batting_order=(1,6)))

TypeError: TeamStack.init() got an unexpected keyword argument 'for_batting_order'

Now I am lost

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Got this Error
LineupOptimizerIncorrectPositionName Traceback (most recent call last)
Cell In[201], line 1
----> 1 optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_positions=['7', '8', '9'], spacing=9999))

File ~\anaconda3\Lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py:342, in LineupOptimizer.add_stack(self, stack)
341 def add_stack(self, stack: BaseStack) -> None:
--> 342 stack.validate(self)
343 self.stacks.append(stack)

File ~\anaconda3\Lib\site-packages\pydfs_lineup_optimizer\stacks.py:210, in TeamStack.validate(self, optimizer)
208 for position in self.for_positions or []:
209 if position not in optimizer.player_pool.available_positions:
--> 210 raise LineupOptimizerIncorrectPositionName('%s is incorrect position name.' % position)

LineupOptimizerIncorrectPositionName: 7 is incorrect position name.

@Milkman9691
Copy link
Author

Tried it as roster_order and got

TypeError Traceback (most recent call last)
Cell In[212], line 1
----> 1 optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_roster_order=['7', '8', '9'], spacing=9999))

TypeError: TeamStack.init() got an unexpected keyword argument 'for_roster_order'

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

TypeError Traceback (most recent call last)
Cell In[234], line 1
----> 1 optimizer.add_stack(TeamStack(3, for_teams=['ATL'], for_roster_order=['7', '8', '9'], spacing=9999))

TypeError: TeamStack.init() got an unexpected keyword argument 'for_roster_order'

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

NameError Traceback (most recent call last)
Cell In[259], line 1
----> 1 players.sort(key=lambda x: x.roster_order)

NameError: name 'players' is not defined

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

I am trying multiple things over here between msgs but I am not being much help but I appreciate evrything you are doing to assist. If I somehow get it I will let you know also. Thx again

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

You want me to send the Excel file along with the Notebook?

@Milkman9691
Copy link
Author

pip install pydfs-lineup-optimizer

from pydfs_lineup_optimizer import get_optimizer, Site, Sport
from pydfs_lineup_optimizer import TeamStack, PlayersGroup
from pydfs_lineup_optimizer.stacks import GameStack, TeamStack, PositionsStack, NestedPlayersGroup, OptimizerStack, Stack

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

optimizer.load_players_from_csv(r"C:\Users\Greg\Downloads\MLB DFS.csv")

optimizer.restrict_positions_for_opposing_team(['SP', 'RP'], ['1B', '1B/2B', '1B/3B', '1B/OF','1B/C','1B/SS', '2B', '2B/C', '2B/3B', '2B/OF', '2B/SS', '3B', '3B/OF', '3B/SS', 'C', 'C/1B', 'C/2B', 'C/OF', 'OF', 'SS','OF/SS', 'SS/OF'])

optimizer.add_stack(TeamStack(4, for_teams=['ATL'], for_positions=['1B', '2B', '3B', 'OF', 'SS'])) #smallest slate <5 games use 5 man stacks

optimizer.add_stack(TeamStack(3, for_teams=['LAA'], for_positions=['1B', '2B', '3B', 'OF', 'SS']))

optimizer.add_stack(TeamStack(2, for_teams=['ATL'], for_positions=['1B', '2B', '3B', 'OF', 'SS']))

SP1 = optimizer.player_pool.get_player_by_name("Nathan Eovaldi")
SP1.min_exposure = .9
SP1.max_exposure = 1

SP2 = optimizer.player_pool.get_player_by_name("Carlos Rodon")
SP2.min_exposure = .9
SP2.max_exposure = 1
#SP2 = optimizer.player_pool.get_player_by_name("Tyler Alexander")
#SP2.min_exposure = .2
#SP2.max_exposure = .2

lineups = optimizer.optimize(n=20)

lineups

lineups = list(optimizer.optimize(20))

lineups

optimizer.export(r'C:\Users\Greg\Downloads\MLB Starters.csv')
for lineup in lineups:
print(lineup)

optimizer.print_statistic()

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

The only additonal column I have in my csv is the Roster Order In that code I did not have any of the code for the Roster Order because it was not doing what I was wanting.

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Got this but i may have something incorrect on my end I kinda rushed

NameError Traceback (most recent call last)
Cell In[4], line 1
----> 1 class CustomTeamStack(TeamStack):
2 def build_stacks(self, players: List[Player], optimizer:
3 'LineupOptimizer') -> List[OptimizerStack]:
4 players = [player for player in players if player.roster_order not
5 in [7, 8, 9] if player.roster_order is not None]

Cell In[4], line 2, in CustomTeamStack()
1 class CustomTeamStack(TeamStack):
----> 2 def build_stacks(self, players: List[Player], optimizer:
3 'LineupOptimizer') -> List[OptimizerStack]:
4 players = [player for player in players if player.roster_order not
5 in [7, 8, 9] if player.roster_order is not None]
6 return super().build_stacks(players, optimizer)

NameError: name 'Player' is not defined

@Milkman9691
Copy link
Author

Had a misalignment but still got same Error

NameError Traceback (most recent call last)
Cell In[30], line 1
----> 1 class CustomTeamStack(TeamStack):
2 def build_stacks(self, players: List[Player], optimizer:'LineupOptimizer') -> List[OptimizerStack]:
3 players = [player for player in players if player.roster_order not in [7, 8, 9] if player.roster_order is not None]

Cell In[30], line 2, in CustomTeamStack()
1 class CustomTeamStack(TeamStack):
----> 2 def build_stacks(self, players: List[Player], optimizer:'LineupOptimizer') -> List[OptimizerStack]:
3 players = [player for player in players if player.roster_order not in [7, 8, 9] if player.roster_order is not None]
4 return super().build_stacks(players, optimizer)

NameError: name 'Player' is not defined

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

That ran perfect with one exception it no longer is showing the lineup order beside the player like it was

*New

  1. P Zack Wheeler SP PHI PHI@STL 21.89 9600.0$
  2. P Merrill Kelly SP ARI ARI@COL 19.19 8400.0$
  3. C J.T. Realmuto C PHI PHI@STL 9.19 4700.0$
  4. 1B Nolan Schanuel 1B LAA TB@LAA 6.71 3600.0$
  5. 2B Ozzie Albies 2B ATL NYM@ATL 8.63 5500.0$
  6. 3B Anthony Rendon 3B LAA TB@LAA 5.83 3400.0$
  7. SS Orlando Arcia SS ATL NYM@ATL 6.31 3600.0$
  8. OF Jarred Kelenic OF ATL NYM@ATL 6.93 3600.0$
  9. OF Michael Harris II OF ATL NYM@ATL 8.54 4400.0$
  10. OF Mickey Moniak OF LAA TB@LAA 7.23 3200.0$

*Old

  1. P Zack Wheeler SP PHI PHI@STL 21.89 9600.0$
  2. P Merrill Kelly SP ARI ARI@COL 19.19 8400.0$
  3. C Gabriel Moreno(2) C ARI ARI@COL 8.0 4100.0$
  4. 1B Jake Cronenworth(3) 1B SD CHC@SD 8.75 4100.0$
  5. 2B Xander Bogaerts(1) 2B SD CHC@SD 8.97 4900.0$
  6. 3B Tyler Wade(9) 3B SD CHC@SD 6.84 2600.0$
  7. SS Jace Peterson(6) SS ARI ARI@COL 8.51 3100.0$
  8. OF Corbin Carroll(1) OF ARI ARI@COL 11.96 5700.0$
  9. OF Joc Pederson(3) OF ARI ARI@COL 10.55 4200.0$
  10. OF Jackson Merrill(8) OF SD CHC@SD 7.57 3200.0$

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Still getting multiple 7,8, 9 batters with it

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Here is the breakdown for this MLB season so far as to how they score
I only count them if they were in the top 20 scorers on the slates
I added by positions how they breakdown below also
You can see after 5th it drops nearly in half and by positions the OF is by far the leading position

*By Batting Order
1 | 15.9%
2 | 14.6%
3 | 15.9%
4 | 12.4%
5 | 12.0%
6 | 8.2%
7 | 7.7%
8 | 7.7%
9 | 5.6%

*Positions
OF | 43.8%
1B | 10.0%
1B/OF | 3.8%
2B/OF | 0.4%
3B | 8.3%
1B/2B | 0.4%
C | 7.1%
2B | 10.0%
SS | 11.7%
2B/3B | 0.4%
2B/SS | 1.7%
3B/SS | 0.8%
3B/OF | 0.4%
1B/3B | 0.8%
1B/C | 0.4%
OF/SS | 0.0%
1B/SS | 0.0%
2B/C | 0.0%
C/OF | 0.0%
3B/C | 0.0%

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

yeah no problem

@Milkman9691
Copy link
Author

Milkman9691 commented Apr 10, 2024 via email

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

why is the email showing up as a bunch of *******. Or am i not savvy enuf to know how to see them yet

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

I believe that is what you were wanting. Let me know if that is correct. It is from last nights Draftkings slate

@Denwen12
Copy link

Denwen12 commented Apr 10, 2024 via email

@Milkman9691
Copy link
Author

Thx for all the help and I am signing off for a bit

@lightninglarry
Copy link

Here is the breakdown for this MLB season so far as to how they score I only count them if they were in the top 20 scorers on the slates I added by positions how they breakdown below also You can see after 5th it drops nearly in half and by positions the OF is by far the leading position

*By Batting Order 1 | 15.9% 2 | 14.6% 3 | 15.9% 4 | 12.4% 5 | 12.0% 6 | 8.2% 7 | 7.7% 8 | 7.7% 9 | 5.6%

*Positions OF | 43.8% 1B | 10.0% 1B/OF | 3.8% 2B/OF | 0.4% 3B | 8.3% 1B/2B | 0.4% C | 7.1% 2B | 10.0% SS | 11.7% 2B/3B | 0.4% 2B/SS | 1.7% 3B/SS | 0.8% 3B/OF | 0.4% 1B/3B | 0.8% 1B/C | 0.4% OF/SS | 0.0% 1B/SS | 0.0% 2B/C | 0.0% C/OF | 0.0% 3B/C | 0.0%

this is DK data right? Would you happen to have FD Data like this? Good stuff man, always looking for an edge.

@Milkman9691
Copy link
Author

Here is the breakdown for this MLB season so far as to how they score I only count them if they were in the top 20 scorers on the slates I added by positions how they breakdown below also You can see after 5th it drops nearly in half and by positions the OF is by far the leading position
*By Batting Order 1 | 15.9% 2 | 14.6% 3 | 15.9% 4 | 12.4% 5 | 12.0% 6 | 8.2% 7 | 7.7% 8 | 7.7% 9 | 5.6%
*Positions OF | 43.8% 1B | 10.0% 1B/OF | 3.8% 2B/OF | 0.4% 3B | 8.3% 1B/2B | 0.4% C | 7.1% 2B | 10.0% SS | 11.7% 2B/3B | 0.4% 2B/SS | 1.7% 3B/SS | 0.8% 3B/OF | 0.4% 1B/3B | 0.8% 1B/C | 0.4% OF/SS | 0.0% 1B/SS | 0.0% 2B/C | 0.0% C/OF | 0.0% 3B/C | 0.0%

this is DK data right? Would you happen to have FD Data like this? Good stuff man, always looking for an edge.

Correct that is DK Data. You could create one for FD in just a few minutes if you want. The more the season progresses the longer it takes to create. I understand the edge part bc I am always looking for one too. I can shoot you several pointers and ideas in a new thread or via email if you want. I consistently get my Pitchers correct every night but the hitters are where the high variance is.

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