When you’re using a tool like dfsOptimizer, it can be helpful to do real-world experiments to fine-tune the methods and constraints you choose to apply when you’re building lineups. For instance, should you stack players? Should you limit the max salary?

To make this easier, you can use the compare_lineups_with_actuals function.

Compare lineups with actual performance

Given a set up lineups generated using build_lineups, the compare_lineups_with_actuals can quickly calculate the real-world value of those lineups, given a data.frame containing actual scores.

An example: You joined a contest on a DFS site, and you didn’t win – you want to see whether you would have performed better in that contest had you done something differently with your lineup construction.

So, you go get the players’ actual fantasy points for that contest, and using compare_lineups_with_actuals, can start testing.

In the following example, actuals is a data.frame with three columns: - id: The player’s ID - fullname: The player’s fullname - actuals: The actual fantasy points for that player

head(actuals)
#>           fullname       id actuals
#> 1:      A.J. Greer 14086739     0.0
#> 2:     Adam Brooks 14086515     2.0
#> 3: Adam Clendening 14086951     0.0
#> 4:    Adam Larsson 14086885     3.0
#> 5:      Adam Lowry 14086495     1.5
#> 6:     Adam Pelech 14086851     0.0
# Build initial model
initial_mod <- create_optimizer('DRAFTKINGS','HOCKEY','CLASSIC')
initial_mod <- add_players_from_df(initial_mod, nhl_players)

# Build 5 lineups with one rule -- max player overlap = 5
mod1 <- set_max_overlap(initial_mod, 5)
lineups_1 <- build_lineups(mod1, 5, verbose = FALSE)
results_1 <- compare_lineups_with_actuals(lineups_1, actuals)

# Now build another 5 lineups with max_overlap of 4, and 
# Max exposure to 50%
mod2 <- initial_mod
mod2 <- set_max_overlap(mod2, 4)
mod2 <- set_max_exposure(mod2, .3)

lineups_2 <- build_lineups(mod2, 5, verbose = FALSE)
results_2 <- compare_lineups_with_actuals(lineups_2, actuals)

By looking at the output of compare_lineups_with_actuals, one can quickly see whether one set of constraints produced a better actual lineup than any other.

results_1
#>      lineup projected_pts actual_pts    diff
#> 1: lineup_3        119.62       26.0  -93.62
#> 2: lineup_1        121.84       25.0  -96.84
#> 3: lineup_2        120.89       24.0  -96.89
#> 4: lineup_5        119.25       16.0 -103.25
#> 5: lineup_4        119.32       15.5 -103.82
results_2
#>      lineup projected_pts actual_pts   diff
#> 1: lineup_3        118.21       30.5 -87.71
#> 2: lineup_5         98.61       26.3 -72.31
#> 3: lineup_1        121.84       25.0 -96.84
#> 4: lineup_2        120.07       22.5 -97.57
#> 5: lineup_4        101.97       18.4 -83.57

In the above example, the second set of constraints (max overlap of 4 and max exposure of 50%) would have resulted in a set of higher scoring lineups.