Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EmilHvitfeldt/90b3946037a5758bfafe6a7a98ad5a09 to your computer and use it in GitHub Desktop.
Save EmilHvitfeldt/90b3946037a5758bfafe6a7a98ad5a09 to your computer and use it in GitHub Desktop.
sparse matrix output step_dummy
library(recipes)
library(nycflights13)


# rec <- recipe(dep_delay ~ carrier + tailnum + origin + dest, data = flights) |>
rec <- recipe(dep_delay ~ tailnum, data = flights[1:100000, ]) |>
  step_dummy(all_nominal_predictors())

options("recipes.sparse" = FALSE)

system.time({
  rec |>
    prep() |>
    bake(NULL, composition = "dgCMatrix")
})
#> Warning: ! There are new levels in a factor: `NA`.
#>    user  system elapsed 
#>  33.799   2.050  36.140

options("recipes.sparse" = TRUE)

system.time({
    rec |>
      prep() |>
      bake(NULL, composition = "dgCMatrix")
})
#>    user  system elapsed 
#>   1.260   0.164   1.430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment