-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting objective in set_engine not respected for xgboost #403
Comments
Fixed in #411 library(parsnip)
library(magrittr)
# boost_tree
model <- parsnip::boost_tree(mtry = NULL, trees = 5, mode = 'regression', learn_rate = .1)
model <- parsnip::set_engine(model, "xgboost", objective = "reg:squaredlogerror")
set.seed(4)
data <- matrix(rnorm(1000), ncol = 4) %>%
as.data.frame() %>%
dplyr::mutate(y = sample(1000/4))
fit <- model %>%
parsnip::fit(y ~., data = data)
predict(fit, data)
#> # A tibble: 250 x 1
#> .pred
#> <dbl>
#> 1 1.20
#> 2 1.20
#> 3 1.20
#> 4 1.20
#> 5 1.20
#> 6 1.20
#> 7 1.20
#> 8 1.20
#> 9 1.20
#> 10 1.20
#> # … with 240 more rows
fit$fit$params$objective
#> [1] "reg:squaredlogerror" Created on 2021-01-14 by the reprex package (v0.3.0) |
Thanks Max. Will head over to treesnip and try (or make them try) to implement the same there. 😄 |
I have on my list a few PRs to submit over there but have not had time. If you want I can include this (if you don't need it right away). |
If you want to do it, I'd surely prefer that 😄. There is already an issue for it as mentioned above just to make sure: curso-r/treesnip#24. Thanks a lot. |
I went ahead and replicate the logic for catboost and lightgbm to spare @topepo’s time. |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
I wanted to use one of the many objectives in xgboost described here.
So I went on and wrote this code to set the
objective
inset_engine()
, as...
are passed to the engine as described in the docs for...
inhelp(set_engine, package = 'parsnip')
:However, I think the objective is not respected, as it is always derived from
mode
, which can only be regression or classification.This problem actually did come up in curso-r/treesnip#24, where I wanted to use the quantile objective for
{lightgbm}
and could not and the answer was: "We just copied that code from parsnip". In the interest of a consistent solution to this problem, I am creating an issue here. As described in curso-r/treesnip#24, the maintainers of{treesnip}
are happy to let the user override the objective, but I thought maybe this topic merits a discussion here, as the same problem applies to{xgboost}
and other engines too.I think it should be possible to override the objective if it is consistent with the
mode
argument, because I it can in some instances be orthogonal to the mode (e.g. in my example, i want to use the squared log error) or specify the mode more precisely, e.g.survival:cox
is a Cox regression, which is consistent withmode = 'regression'
conceptually I think.The text was updated successfully, but these errors were encountered: