-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ Suggests: | |
callr, | ||
caret, | ||
covr, | ||
dbarts, | ||
embed, | ||
h2o, | ||
keras, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#' @templateVar class a `bart` | ||
#' @template title_desc | ||
#' | ||
#' @templateVar outclass `bundled_bart` | ||
#' @templateVar default . | ||
#' @template return_bundle | ||
#' @family bundlers | ||
#' | ||
#' @param x A `bart` object returned from [dbarts::bart()]. Notably, this ought | ||
#' not to be the output of [parsnip::bart()]. | ||
#' @template param_unused_dots | ||
#' @rdname bundle_bart | ||
#' @template butcher_details | ||
#' @examplesIf rlang::is_installed(c("dbarts")) | ||
#' # fit model and bundle ------------------------------------------------ | ||
#' library(dbarts) | ||
#' | ||
#' mtcars$vs <- as.factor(mtcars$vs) | ||
#' | ||
#' set.seed(1) | ||
#' fit <- dbarts::bart(mtcars[c("disp", "hp")], mtcars$vs, keeptrees = TRUE) | ||
#' | ||
#' fit_bundle <- bundle(fit) | ||
#' | ||
#' # then, after saveRDS + readRDS or passing to a new session ---------- | ||
#' fit_unbundled <- unbundle(fit_bundle) | ||
#' | ||
#' fit_unbundled_preds <- predict(fit_unbundled, mtcars) | ||
#' @aliases bundle.bart | ||
#' @method bundle bart | ||
#' @export | ||
bundle.bart <- function(x, ...) { | ||
rlang::check_installed("dbarts") | ||
rlang::check_dots_empty() | ||
|
||
# `parsnip::bart()` and `dbarts::bart()` unfortunately both inherit from `bart` | ||
if (inherits(x, "model_spec")) { | ||
rlang::abort(c( | ||
paste0("`x` should be the output of `dbarts::bart()`, not a model ", | ||
"specification from `parsnip::bart()`."), | ||
"To bundle `parsnip::bart()` output, train it with `parsnip::fit()` first." | ||
)) | ||
} | ||
|
||
if (is.null(x$fit)) { | ||
rlang::abort(c( | ||
"`x` can't be bundled.", | ||
"`x` must have been fitted with argument `keeptrees = TRUE`." | ||
)) | ||
} | ||
|
||
# "touch" the object's state (#64) | ||
invisible(x$fit$state) | ||
|
||
bundle_constr( | ||
object = x, | ||
situate = situate_constr(identity), | ||
desc_class = class(x)[1] | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# bundle.bart errors informatively with model_spec input (#64) | ||
|
||
Code | ||
bundle(parsnip::bart()) | ||
Condition | ||
Error in `bundle()`: | ||
! `x` should be the output of `dbarts::bart()`, not a model specification from `parsnip::bart()`. | ||
* To bundle `parsnip::bart()` output, train it with `parsnip::fit()` first. | ||
|
||
# bundle.bart errors informatively when `keeptrees = FALSE` (#64) | ||
|
||
Code | ||
bundle(fit) | ||
Condition | ||
Error in `bundle()`: | ||
! `x` can't be bundled. | ||
* `x` must have been fitted with argument `keeptrees = TRUE`. | ||
|