-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbundle_catboost.Rd
More file actions
117 lines (99 loc) · 4.64 KB
/
bundle_catboost.Rd
File metadata and controls
117 lines (99 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bundle_catboost.R
\name{bundle.catboost.Model}
\alias{bundle.catboost.Model}
\title{Bundle a \code{catboost.Model} object}
\usage{
\method{bundle}{catboost.Model}(x, ...)
}
\arguments{
\item{x}{A \code{catboost.Model} object returned from \code{catboost::catboost.train()}.}
\item{...}{Not used in this bundler and included for compatibility with
the generic only. Additional arguments passed to this method will return
an error.}
}
\value{
A bundle object with subclass \code{bundled_catboost.Model}.
Bundles are a list subclass with two components:
\item{object}{An R object. Gives the output of native serialization
methods from the model-supplying package, sometimes with additional
classes or attributes that aid portability. This is often
a \link[base:raw]{raw} object.}
\item{situate}{A function. The \code{situate()} function is defined when
\code{\link[=bundle]{bundle()}} is called, though is a loose analogue of an \code{\link[=unbundle]{unbundle()}} S3
method for that object. Since the function is defined on \code{\link[=bundle]{bundle()}}, it
has access to references and dependency information that can
be saved alongside the \code{object} component. Calling \code{\link[=unbundle]{unbundle()}} on a
bundled object \code{x} calls \code{x$situate(x$object)}, returning the
unserialized version of \code{object}. \code{situate()} will also restore needed
references, such as server instances and environmental variables.}
Bundles are R objects that represent a "standalone" version of their
analogous model object. Thus, bundles are ready for saving to a file; saving
with \code{\link[base:readRDS]{base::saveRDS()}} is our recommended serialization strategy for bundles,
unless documented otherwise for a specific method.
To restore the original model object \code{x} in a new environment, load its
bundle with \code{\link[base:readRDS]{base::readRDS()}} and run \code{\link[=unbundle]{unbundle()}} on it. The output
of \code{\link[=unbundle]{unbundle()}} is a model object that is ready to \code{\link[=predict]{predict()}} on new data,
and other restored functionality (like plotting or summarizing) is supported
as a side effect only.
The bundle package wraps native serialization methods from model-supplying
packages. Between versions, those model-supplying packages may change their
native serialization methods, possibly introducing problems with re-loading
objects serialized with previous package versions. The bundle package does
not provide checks for these sorts of changes, and ought to be used in
conjunction with tooling for managing and monitoring model environments
like \link[vetiver:vetiver-package]{vetiver} or \link[renv:renv-package]{renv}.
See \code{vignette("bundle")} for more information on bundling and its motivation.
}
\description{
Bundling a model prepares it to be saved to a file and later
restored for prediction in a new R session. See the 'Value' section for
more information on bundles and their usage.
}
\section{bundle and butcher}{
The \href{https://butcher.tidymodels.org/}{butcher} package allows you to remove
parts of a fitted model object that are not needed for prediction.
This bundle method is compatible with pre-butchering. That is, for a
fitted model \code{x}, you can safely call:
\if{html}{\out{<div class="sourceCode">}}\preformatted{res <-
x |>
butcher() |>
bundle()
}\if{html}{\out{</div>}}
and predict with the output of \code{unbundle(res)} in a new R session.
}
\examples{
\dontshow{if (rlang::is_installed(c("catboost", "parsnip", "bonsai"))) withAutoprint(\{ # examplesIf}
# fit model and bundle ------------------------------------------------
library(parsnip)
library(bonsai)
set.seed(1)
mod <- boost_tree(trees = 10) \%>\%
set_engine("catboost", verbose = 0) \%>\%
set_mode("classification") \%>\%
fit(Species ~ ., data = iris)
# extract the underlying catboost model
catboost_model <- mod$fit
model_bundle <- bundle(catboost_model)
# then, after saveRDS + readRDS or passing to a new session ----------
model_unbundled <- unbundle(model_bundle)
\dontshow{\}) # examplesIf}
}
\seealso{
This method stores the raw serialized model bytes from the
catboost model object and restores the C++ handle on unbundle.
Other bundlers:
\code{\link{bundle}()},
\code{\link{bundle.H2OAutoML}()},
\code{\link{bundle.bart}()},
\code{\link{bundle.keras.engine.training.Model}()},
\code{\link{bundle.luz_module_fitted}()},
\code{\link{bundle.model_fit}()},
\code{\link{bundle.model_stack}()},
\code{\link{bundle.recipe}()},
\code{\link{bundle.step_umap}()},
\code{\link{bundle.train}()},
\code{\link{bundle.workflow}()},
\code{\link{bundle.xgb.Booster}()}
}
\concept{bundlers}