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

Update axe methods for xgboost #218

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ S3method(axe_ctrl,randomForest)
S3method(axe_ctrl,rpart)
S3method(axe_ctrl,train)
S3method(axe_ctrl,train.recipe)
S3method(axe_ctrl,xgb.Booster)
S3method(axe_data,classbagg)
S3method(axe_data,default)
S3method(axe_data,earth)
Expand Down Expand Up @@ -95,7 +94,6 @@ S3method(axe_fitted,ranger)
S3method(axe_fitted,recipe)
S3method(axe_fitted,train)
S3method(axe_fitted,train.recipe)
S3method(axe_fitted,xgb.Booster)
S3method(weigh,default)
S3method(weigh,ksvm)
S3method(weigh,model_fit)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

* Added an `axe_fitted()` method to butcher the `template` slot for prepped
recipes (@AshesITR, #207).

* Removed `axe_fitted()` and `axe_ctrl()` for xgboost, because these methods
caused problems for prediction (#218).

# butcher 0.1.5

Expand Down
35 changes: 0 additions & 35 deletions R/xgb.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@ axe_call.xgb.Booster <- function(x, verbose = FALSE, ...) {
)
}

#' Remove controls used for training.
#'
#' @rdname axe-xgb.Booster
#' @export
axe_ctrl.xgb.Booster <- function(x, verbose = FALSE, ...) {
old <- x
x <- exchange(x, "params", list(NULL))

add_butcher_attributes(
x,
old,
disabled = c("print()"),
add_class = FALSE,
verbose = verbose
)
}

#' Remove environments.
#'
#' @rdname axe-xgb.Booster
Expand All @@ -93,21 +76,3 @@ axe_env.xgb.Booster <- function(x, verbose = FALSE, ...) {
verbose = verbose
)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably remove axe_env.xgb.Booster too. It seems like callbacks are an optional feature, and it seems like they are only used at training time, but I can't confirm this. Since they are optional and probably don't take up space by default, I think removing this potentially harmful method is the safer thing to do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I see

#>  1 callbacks.cb.evaluation.log   0.0354  
#>  2 callbacks.cb.print.evaluation 0.0146  

in the weigh results, which does get smaller when you axe it.

I guess those are default callbacks that get added by xgboost. I guess we should leave this method in there then

#' Remove cached memory dump of xgboost model that was saved as a raw
#' data type.
#'
#' @rdname axe-xgb.Booster
#' @export
axe_fitted.xgb.Booster <- function(x, verbose = FALSE, ...) {
old <- x
x <- exchange(x, "raw", raw())

add_butcher_attributes(
x,
old,
disabled = c("xgb.Booster.complete()"),
add_class = FALSE,
verbose = verbose
)
}
6 changes: 0 additions & 6 deletions man/axe-xgb.Booster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions tests/testthat/test-xgb.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ test_that("xgb.Booster + linear solver + predict() works", {
expect_equal(x$call, rlang::expr(dummy_call()))
x <- axe_env(bst)
expect_lt(lobstr::obj_size(x), lobstr::obj_size(bst))
x <- axe_ctrl(bst)
expect_equal(x$params, list(NULL))
x <- axe_fitted(bst)
expect_equal(x$raw, raw())
x <- butcher(bst)
expect_equal(xgb.importance(model = x),
xgb.importance(model = bst))
Expand Down Expand Up @@ -54,10 +50,6 @@ test_that("xgb.Booster + tree-learning algo + predict() works", {
expect_equal(x$call, rlang::expr(dummy_call()))
x <- axe_env(bst)
expect_lt(lobstr::obj_size(x), lobstr::obj_size(bst))
x <- axe_ctrl(bst)
expect_equal(x$params, list(NULL))
x <- axe_fitted(bst)
expect_equal(x$raw, raw())
x <- butcher(bst)
expect_equal(xgb.importance(model = x),
xgb.importance(model = bst))
Expand Down