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

pass along nfeatures and feature_names to xgboost bundle #67

Merged
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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Added bundle method for objects from `dbarts::bart()` and, by extension,
`parsnip::bart(engine = "dbarts")` (#64).

* Bundling xgboost objects now takes extra steps to preserve `nfeatures` and `feature_names` (#67).

# bundle 0.1.1

* Fixed bundling of recipes steps situated inside of workflows.
Expand Down
3 changes: 3 additions & 0 deletions R/bundle_xgboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ bundle.xgb.Booster <- function(x, ...) {
num_class = !!x$params$num_class
)

res$nfeatures <- !!x$nfeatures
res$feature_names <- !!x$feature_names

res
}),
desc_class = class(x)[1]
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_bundle_xgboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ test_that("bundling + unbundling xgboost fits", {
# compare predictions
expect_equal(mod_preds, mod_unbundled_preds)
expect_equal(mod_preds, mod_butchered_unbundled_preds)

# verify nfeatures and feature_names are kept
expect_identical(unbundle(mod_bundle)$nfeatures, mod_fit$nfeatures)
expect_identical(unbundle(mod_bundle)$feature_names, mod_fit$feature_names)
})
Loading