Skip to content

Commit 51fbfb4

Browse files
pass along nfeatures and feature_names to xgboost bundle (#67)
* pass along nfeatures and feature_names to xgboost bundle * add tests * Update NEWS --------- Co-authored-by: Julia Silge <julia.silge@gmail.com>
1 parent da505eb commit 51fbfb4

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Added bundle method for objects from `dbarts::bart()` and, by extension,
44
`parsnip::bart(engine = "dbarts")` (#64).
55

6+
* Bundling xgboost objects now takes extra steps to preserve `nfeatures` and `feature_names` (#67).
7+
68
# bundle 0.1.1
79

810
* Fixed bundling of recipes steps situated inside of workflows.

R/bundle_xgboost.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ bundle.xgb.Booster <- function(x, ...) {
5151
num_class = !!x$params$num_class
5252
)
5353

54+
res$nfeatures <- !!x$nfeatures
55+
res$feature_names <- !!x$feature_names
56+
5457
res
5558
}),
5659
desc_class = class(x)[1]

tests/testthat/test_bundle_xgboost.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ test_that("bundling + unbundling xgboost fits", {
9696
# compare predictions
9797
expect_equal(mod_preds, mod_unbundled_preds)
9898
expect_equal(mod_preds, mod_butchered_unbundled_preds)
99+
100+
# verify nfeatures and feature_names are kept
101+
expect_identical(unbundle(mod_bundle)$nfeatures, mod_fit$nfeatures)
102+
expect_identical(unbundle(mod_bundle)$feature_names, mod_fit$feature_names)
99103
})

0 commit comments

Comments
 (0)