Skip to content

subset_covariates does not successfully reorder covariates to match training structure #428

Open

Description

@jeremyrcoyle

Error is here: https://github.com/tlverse/sl3/blob/master/R/Lrnr_base.R#L75-L78
This can cause errors in prediction when covariates are reordered relative to training.

Example:

data(mtcars)
lrnr <- Lrnr_glmnet$new()
task1 <- make_sl3_Task(mtcars, outcome="mpg", covariates = c("hp","disp","cyl"))
task2 <- make_sl3_Task(mtcars, outcome="mpg", covariates = c("disp","cyl","hp"))
fit <- lrnr$train(task1)
fit$predict(task1)
fit$predict(task2)
> fit$predict(task1)
 [1] 22.17332 22.17332 25.84009 20.33786 15.04299 21.02797 14.03433 25.56196 25.19695 21.84366 21.84366 16.54794 16.54794 16.54794 12.51304 12.59369 12.75214 26.77790 27.03582
[20] 26.93466 25.55582 16.18985 16.45206 14.22162 14.29382 26.77229 25.63854 25.79350 13.92912 21.51765 13.84251 25.36606
> fit$predict(task2)
 [1] -163.87883 -163.87883  -99.88659 -283.82522 -409.91359 -243.34146 -411.22464 -146.67257 -140.06937 -173.42427 -173.42427 -306.95126 -306.95126 -306.95126 -547.55706
[16] -533.05704 -508.85912  -63.51938  -59.58534  -54.19868 -114.77121 -358.03977 -340.90457 -398.98521 -458.87130  -63.88656 -114.90363  -84.47231 -400.56501 -146.73708
[31] -340.69764 -116.09751

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions