dfs-with-r / coach

Lineup optimization for daily fantasy sports
https://dfs-with-r.github.io/coach/
GNU General Public License v3.0
46 stars 14 forks source link

optimize_generic generating same lineup over and over #14

Closed corycone closed 4 years ago

corycone commented 4 years ago

Hey, this package is outstanding! Only issue I'm running into (and I only just started experimenting with it) is that the optimize_generic, using the model_fd_nfl(data) is just generating the same lineup over and over. I've tried with 3 to 50 lineups, and they are all the same. EDIT: Sorry, the first one is unique, but all the others are identical. If I add a stack size of 3 or more, then all 10 are the same.

Could I be missing a step, or perhaps there's a bug? I've attached a run for 10 lineups so you can see results. Thanks! optimize 10 lineups.txt

zamorarr commented 4 years ago

hi @corycone. Thanks for using the package! This is very strange - definitely not supposed to be happening. Can you attach the data/code you used to generate these? It would help me try and diagnose the issue

corycone commented 4 years ago

Thank you for your reply! Fair warning: I have only been using R since ~ January, so what you see in my script is probably not the cleanest way of attaching my projections (and I don't doubt something I've done here is causing the issue). I've also attached the projections file if that helps. my_coach_script.txt projections.xlsx

corycone commented 4 years ago

Woops: ignore this part: model <- add_existing_roster_constraint(model, roster_rowids) That was me just messing around. That's of course not part of it.

zamorarr commented 4 years ago

No worries - no need to defend the state of your code! But do you have the file fd_players.csv as well?

corycone commented 4 years ago

Yes, sorry about that! Attached. (had to change to .txt to upload. It was .csv) fd_players.txt

zamorarr commented 4 years ago

Ah got it. This one happens to people a lot. I need to add a check to the model to ensure this doesn't happen. The issue is that your row_ids are no longer sequential after you do the inner_join(). This is because you are filtering out rows for players that you do not have projections for.

Your joined_data has 265 rows but the row_ids go up to 418. The way the bans, locks, and roster_constraints work is based off the row_ids, so they need to be sequential! The way to fix that in your case is to add the following line after you create the joined_data:

joined_data <- joined_data %>% mutate(row_id = row_number())

This will re-generate the row-ids in sequential order. Let me know if that solves your issue.

corycone commented 4 years ago

That did it! I think I'll also just toss 0 into the people who I was excluding before to bypass this issue entirely. Thank you very much!