Closed dachel12 closed 5 years ago
Hi, I just released new version of library with team stacking constraint, it probably what you want. If you want that all hitters will be selected from same team you can use it with another constraint set_positions_for_same_team
. If you want to restrict selecting hitters only from 3 team you can remove other hitters from optimization or set max_exposure
to 0 for those players.
Thank you for the quick response. I was thinking something a little different. I would want it so that the optimizer would be the one to handle limiting to x number of teams in each lineup. The goal would be for multi-entry, so I would want to cover a variety of team combinations in a single run. This wouldn't be possible with setting max exposure to 0 on the other players or removing them. Also having the optimizer to use players within x lineup spots in the order from each other would help with grouping players together that might correlate together (player x gets a hit, then player y 2 spots later hits him in).
For now you optimizer hasn't constraint for restricting total number of different teams in lineup, for now you can try to use team stacking constraint that allows you to specify how many players from same team will appear in result lineup. For example: optimizer.set_team_stacking([3, 3, 4])
DK MLB has 10 players in lineup and you specify all 10 players in stacking, so you will get lineups with only 3 different teams.
According to second part of issue, I didn't understand idea of what you want, could you give me example how it should work? Probably you can achieve this with existed constraints.
Cool, thank you. I will try the team stacking constraint. The other option is less important for me, and is unique only to baseball. In baseball, it is common to make a stack of batters that are near each other in the lineup. It is not standard in DK's player pool to include the order, but could be added to the csv as a new column. the constraint i was thinking of would allow you to set a range for what spot in the batter order they hit in. So if I was to set it at 9, the optimizer could use any combination of hitters, but if I was to set it to 4, the optimizer would limit batters from the same team in a lineup to 1-4, 2-5, 8-2, etc. Again, less critical to me, but might be nice to have if it is not a significant amount of work. Thanks again. Really like this optimizer.
Dima, thank you for all the hard work. I hope you're making money on DFS!
I noticed the solver completely bogs down after using the set_team_stacking feature. It seems to only be able to create one or two lineups. Is there anything we can do about this? Or is it just simply too much to solve for?
@dachel12 I think it's not hard, but I'm not sure what api I should implement for this, because dfs sites doesn't provide this information, so it's not clear where user can get this ordering. @brente33 It strange because it works for me. I just set team stacks to [3, 3, 4] (hardest to optimize) for 600 players csv and it's take 2.5x more time then without stacking for generating 10 lineups. Are you using team stacking in combination with other constraint? Maybe some combinations can cause this, I'm not sure.
I deleted all constraints and it still only solved for 1 lineup. I updated to version 2.4 today, I’m not sure what is happening.
Sent from my iPhone
On Apr 22, 2019, at 12:37 PM, Dima Kudosh notifications@github.com<mailto:notifications@github.com> wrote:
@dachel12https://github.com/dachel12 I think it's not hard, but I'm not sure what api I should implement for this, because dfs sites doesn't provide this information, so it's not clear where user can get this ordering. @brente33https://github.com/brente33 It strange because it works for me. I just set team stacks to [3, 3, 4] (hardest to optimize) for 600 players csv and it's take 2.5x more time then without stacking for generating 10 lineups. Are you using team stacking in combination with other constraint? Maybe some combinations can cause this, I'm not sure.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/55#issuecomment-485469729, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKX3JKFLGVU2CY7JAR4ZVU3PRXSV5ANCNFSM4HHKYOUA.
Could you send csv file with players and exact parameters that you pass to team stacking method to my email? I'll try to investigate why it works slowly.
This is the stripped down code I'm running. When I use n=1, n=4, or n=5 it works fine. If I use n=2, n=3, or n>5 it stops after 1 lineup.
from pydfs_lineup_optimizer import Site, Sport, get_optimizer optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL) optimizer.load_players_from_csv("fanduel-MLB.csv")
for lineup in optimizer.optimize(n=2): print(lineup)
I had no problems at all running your optimizer until after I updated to version 2.4. I pulled it from GIT first. The I deleted everything and tried it new but that didn't help either.
From: Dima Kudosh notifications@github.com Sent: Monday, April 22, 2019 1:41 PM To: DimaKudosh/pydfs-lineup-optimizer Cc: brente33; Mention Subject: Re: [DimaKudosh/pydfs-lineup-optimizer] Feature Request: MLB Teams in each lineup and order range (#55)
Could you send csv file with players and exact parameters that you pass to team stacking method to my email? I'll try to investigate why it works slowly.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/55#issuecomment-485489315, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKX3JKDVF6V2X47JAGVPWL3PRX2FPANCNFSM4HHKYOUA.
Do you have hangs with simple optimization? On this release I changed some solver settings, maybe they can cause this, try init your optimizer like this:
from pydfs_lineup_optimizer.solvers.pulp_solver import PuLPSolver
class CustomPuLPSolver(PuLPSolver):
LP_SOLVER = None
optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL, solver=CustomPuLPSolver)
You are the man, that worked. Really appreciate you creating the optimizer and taking the time to help out!
From: Dima Kudosh notifications@github.com Sent: Monday, April 22, 2019 2:44 PM To: DimaKudosh/pydfs-lineup-optimizer Cc: brente33; Mention Subject: Re: [DimaKudosh/pydfs-lineup-optimizer] Feature Request: MLB Teams in each lineup and order range (#55)
Do you have hangs with simple optimization? On this release I changed some solver settings, maybe they can cause this, try init your optimizer like this:
from pydfs_lineup_optimizer.solvers.pulp_solver import PuLPSolver
class CustomPuLPSolver(PuLPSolver): LP_SOLVER = None
optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL, solver=CustomPuLPSolver)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/55#issuecomment-485509517, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKX3JKFYP7MGZY6GXP7PNT3PRYBRZANCNFSM4HHKYOUA.
@DimaKudosh totally agree with you. That would make it difficult for people to use that feature. Would it make sense to write the code as if there would be an additional column in the players file, but comment it out so that it is not active by default? Otherwise I am 100% okay with leaving optimizer as is. Thank you very much for discussing these features with me.
@brente33 You are welcome! Strange that my changes slow-down your program. Can you say what version of python you are using and how many cores on your pc. Also what is output of import pulp; pulp.VERSION
and import multiprocessing; multiprocessing.cpu_count()
? I'll try to investigate reason of this issue, because I tried run new version on 2 different pc and it works faster than previous.
@dachel12 I can check for additional column when parsing csv as I do for max_exposure, but it's not clear, in your example you wrote that if we set spot spacing to 4 optimizer should limit players to 1-4, why it should limit to 1-4, it's 2 players between 1 and 4 not 4.
Sorry, the way I worded it may have been confusing. You're thinking about it correctly. If I was to limit the range to 4 then it could be (for example) any number of players between 1 and 4 in the order. Just that the range between where they are in the order should be whatever is set.
I taught myself python just to be able to use your solver so try not laugh too hard at my coding skills.... I'm using JetBrains PyCharm Edu 2018.2
This is what I get when I run pulp:
[cid:f4b52411-d653-4eb1-a746-7f6eb1925ef2]
I don't play a lot of money on DFS but if I ever hit anything big I'll pay you something for all of this!
From: Dima Kudosh notifications@github.com Sent: Monday, April 22, 2019 3:23 PM To: DimaKudosh/pydfs-lineup-optimizer Cc: brente33; Mention Subject: Re: [DimaKudosh/pydfs-lineup-optimizer] Feature Request: MLB Teams in each lineup and order range (#55)
@brente33https://github.com/brente33 You are welcome! Strange that my changes slow-down your program. Can you say what version of python you are using and how many cores on your pc. Also what is output of import pulp; pulp.VERSION and import multiprocessing; multiprocessing.cpu_count()? I'll try to investigate reason of this issue, because I tried run new version on 2 different pc and it works faster than previous. @dachel12https://github.com/dachel12 I can check for additional column when parsing csv as I do for max_exposure, but it's not clear, in your example you wrote that if we set spot spacing to 4 optimizer should limit players to 1-4, why it should limit to 1-4, it's 2 players between 1 and 4 not 4.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/55#issuecomment-485521683, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKX3JKFVNADQWQSCNB4Q6ITPRYGDZANCNFSM4HHKYOUA.
@DimaKudosh Thank you for making this optimizer! After upgrading to version 2.4 I experienced the same issue that brente33 described which was fixed by your suggestion in this thread. I had a little luck from increasing the number of threads for LP_Solver, but changing to None got it running smoothly again.
I'm using Python 3.7 and the same IDE as brente. CPU count is 4 and pulp version is 1.6.9.
Thanks again.
@kpm1988 I have same pc setup. What OS are you using?
@DimaKudosh I'm using Windows 10.
@kpm1988 I'm using ubuntu, probably it's problem with solver binaries for windows, I can't change it because it comes from PuLP, I'll remove additional solver settings in new minor release.
Thanks @DimaKudosh ! I have Ubuntu installed on another machine, would you recommend using that for now, or would it work the same with the LP_SOLVER = None code you recommended above?
@kpm1988 I think it will be same, I just released version 2.4.1 with remove default solver, so you can just update library instead of overriding solver class.
@DimaKudosh Thanks for the help with setting up stacking. However, last night I noticed I had some teams with batters against my pitcher. Here is how I had the position constraint set up. My DK salaries page was the export from Draftkings with only the avg points column changed to update with the projections I was using.
optimizer.restrict_positions_for_opposing_team(['P'], ['1B', '2B', '3B', 'SS', 'C', 'OF', 'P'])
Any idea why some batters vs pitchers made it through?
I think it because DK split pitcher position into 2 separate positions SP and RP, so imported players actually has SP or RP positions instead of P, try to change your code to:
optimizer.restrict_positions_for_opposing_team(['SP', 'RP'], ['1B', '2B', '3B', 'SS', 'C', 'OF', 'SP', 'RP'])
Thank you, I believe that fixed it. I had 5/20 lineups initially with the P vs opp batter. After updating to that, there were 0.
optimizer.restrict_positions_for_opposing_team(['SP', 'RP'], ['1B', '2B', '3B', 'SS', 'C', 'OF', 'SP', 'RP'])
Is this actually correct? Having no 'SP' vs '1B' from opposite team is understandable. But having no 'SP' vs 'SP' from opposite team is not beneficial. Isn't it should be like this: optimizer.restrict_positions_for_opposing_team(['SP', 'RP'], ['1B', '2B', '3B', 'SS', 'C', 'OF'])
No SP vs SP allows both pitchers to get the win bonus. But yes, not needed. I added that to mine and I think it carried over to Dima's reply to me
Hi, how do you load the pitchers and hitters from CSV file? I was able to get an export for DraftKings MLB pitchers and batters as 2 separate files from rotogrinders.
Bryan,
The optimizer wants the player list in the Draftkings format, so go to draftkings and export the player list for the contest you are entering. If you are trying to load in the projections for the rotogrinders exports, open up the draftkings player list and update the average points column with the projections from rotogrinders and resave the draftkings csv. Import that as your players into the optimizer.
I always save the draftkings export into the same location with the same name so I don't have to update the code to tell it to open a different file. Hope this helps.
Matt
On Sat, Jul 27, 2019 at 12:24 PM Bryan Choi notifications@github.com wrote:
Hi, how do you load the pitchers and hitters from CSV file? I was able to get an export for DraftKings MLB pitchers and batters as 2 separate files from rotogrinders.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/55?email_source=notifications&email_token=AEXOIW72QX2TXQAOJDPLY4LQBSAEPA5CNFSM4HHKYOUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD26PNWY#issuecomment-515700443, or mute the thread https://github.com/notifications/unsubscribe-auth/AEXOIW3Q4Z4S5WR4D6OPPQ3QBSAEPANCNFSM4HHKYOUA .
Would you be able to add 2 constraints to the BASEBALL optimizer? I would like to be able to control how many teams are in my lineups (preferably just the hitters, but if it's easier to do all players that's fine). I would also like to control how far apart my stacks are from each other in the lineup. Ideally, I am hoping to be able to have the optimizer construct lineups with roughly 3 teams for the hitters and the hitters from those teams to be within x number of spots in the order from each other.