如何设定“预算”使用mlr3tuningspaces进行XGBOOST超频带优化的标签?

发布于 2025-02-09 22:45:14 字数 1177 浏览 2 评论 0原文

我试图用 hyperband 来调整 xgboost ,我想从 mlr3tuningspacespaces 软件包中使用建议的默认调谐空间。但是,在使用lts时,我找不到如何用“预算”标记使用“预算”的超参数。

下面,我复制了 mlr3hyperband 包装示例,以说明我的问题:

library(mlr3verse)
library(mlr3hyperband)
library(mlr3tuningspaces)

## this does not work, because I don't know how to tag a hyperparameter 
## with "budget" while using the suggested tuning space
search_space = lts("classif.xgboost.default")
search_space$values

## this works because it has a hyperparameter (nrounds) tagged with "bugdget"
search_space = ps(
  nrounds = p_int(lower = 1, upper = 16, tags = "budget"), 
  eta = p_dbl(lower = 0, upper = 1),
  booster = p_fct(levels = c("gbtree", "gblinear", "dart"))
)

# hyperparameter tuning on the pima indians diabetes data set
instance = tune(
  method = "hyperband",
  task = tsk("pima"),
  learner = lrn("classif.xgboost", eval_metric = "logloss"),
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  search_space = search_space,
  term_evals = 100
)

# best performing hyperparameter configuration
instance$result

I am trying to tune xgboost with hyperband and I would like to use the suggested default tuning space from the mlr3tuningspaces package. However, I don't find how to tag a hyperparameter with "budget" while using lts .

Below, I reproduced the mlr3hyperband package example to illustrate my issue:

library(mlr3verse)
library(mlr3hyperband)
library(mlr3tuningspaces)

## this does not work, because I don't know how to tag a hyperparameter 
## with "budget" while using the suggested tuning space
search_space = lts("classif.xgboost.default")
search_space$values

## this works because it has a hyperparameter (nrounds) tagged with "bugdget"
search_space = ps(
  nrounds = p_int(lower = 1, upper = 16, tags = "budget"), 
  eta = p_dbl(lower = 0, upper = 1),
  booster = p_fct(levels = c("gbtree", "gblinear", "dart"))
)

# hyperparameter tuning on the pima indians diabetes data set
instance = tune(
  method = "hyperband",
  task = tsk("pima"),
  learner = lrn("classif.xgboost", eval_metric = "logloss"),
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  search_space = search_space,
  term_evals = 100
)

# best performing hyperparameter configuration
instance$result

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

維他命╮ 2025-02-16 22:45:14

感谢您指出的。我将将预算标签添加到默认搜索空间中。在此之前,您可以使用此代码。

library(mlr3hyperband)
library(mlr3tuningspaces)
library(mlr3learners)

# get learner with search space in one go
learner = lts(lrn("classif.xgboost"))

# overwrite nrounds with budget tag
learner$param_set$values$nrounds = to_tune(p_int(1000, 5000, tags = "budget"))

instance = tune(
  method = "hyperband",
  task = tsk("pima"),
  learner = learner,
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  term_evals = 100
)

更新28.06.2022

版本0.3.0中的新API是

learner = lts(lrn("classif.xgboost"), nrounds = to_tune(p_int(1000, 5000, tags = "budget"))

Thanks for pointing this out. I will add the budget tag to the default search space. Until then you can use this code.

library(mlr3hyperband)
library(mlr3tuningspaces)
library(mlr3learners)

# get learner with search space in one go
learner = lts(lrn("classif.xgboost"))

# overwrite nrounds with budget tag
learner$param_set$values$nrounds = to_tune(p_int(1000, 5000, tags = "budget"))

instance = tune(
  method = "hyperband",
  task = tsk("pima"),
  learner = learner,
  resampling = rsmp("cv", folds = 3),
  measures = msr("classif.ce"),
  term_evals = 100
)

Update 28.06.2022

The new API in version 0.3.0 is

learner = lts(lrn("classif.xgboost"), nrounds = to_tune(p_int(1000, 5000, tags = "budget"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文