Skip to content
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

Support for LightGBM multiclassova Multi-Class (one-vs-all) Objective #93

Open
JavOrraca opened this issue Nov 6, 2024 · 2 comments
Open

Comments

@JavOrraca
Copy link

I recently discovered that LightGBM has a multiclassova objective function (multi-class one-vs-all) that treats multi-class classification as a set of binary classification tasks. Getting quite decent results with this approach when passed directly to lightgbm::lgb.train(), but I'm not sure if the internal process_objective_function() overrides any objective function manually inserted in set_engine(), for example:

set_engine("lightgbm", params = list(objective = "multiclassova"))

Thanks for your help!

@simonpcouch
Copy link
Contributor

Thanks for the issue! You can set lightgbm params by passing the desired parameter directly to set_engine() rather than as an element of set_engine(param):

library(bonsai)
#> Loading required package: parsnip

mtcars$gear <- as.factor(mtcars$gear)

spec <-
  boost_tree(mode = "classification", engine = "lightgbm") %>%
  set_engine("lightgbm", objective = "multiclassova", num_classes = length(unique(mtcars$gear)))

fit(spec, gear ~ ., mtcars)
#> parsnip model object
#> 
#> LightGBM Model (1 tree)
#> Objective: multiclassova (3 classes)
#> Fitted to dataset with 10 columns

Created on 2024-11-07 with reprex v2.1.1

Will leave this issue open as this surfaced a few issues.

  1. I thought this was more clearly documented but I didn't find the relevant docs in the first 2 pages I looked to
  2. I thought train_lightgbm() handled an explicit params argument more gracefully than it seems to.
  3. process_objective_function() could set num_classes for the user even with an explicitly-set objective function.

@JavOrraca
Copy link
Author

Ah, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants