2222# ' }
2323# ' These arguments are converted to their specific names at the
2424# ' time that the model is fit. Other options and argument can be
25- # ' set using the `...` slot . If left to their defaults
25+ # ' set using the `set_engine` function . If left to their defaults
2626# ' here (`NULL`), the values are taken from the underlying model
2727# ' functions. If parameters need to be modified, `update` can be used
2828# ' in lieu of recreating the object from scratch.
4646# ' @param sample_size An number for the number (or proportion) of data that is
4747# ' exposed to the fitting routine. For `xgboost`, the sampling is done at at
4848# ' each iteration while `C5.0` samples once during traning.
49- # ' @param ... Other arguments to pass to the specific engine's
50- # ' model fit function (see the Engine Details section below). This
51- # ' should not include arguments defined by the main parameters to
52- # ' this function. For the `update` function, the ellipses can
53- # ' contain the primary arguments or any others.
5449# ' @details
5550# ' The data given to the function are not saved and are only used
5651# ' to determine the _mode_ of the model. For `boost_tree`, the
6358# ' \item \pkg{Spark}: `"spark"`
6459# ' }
6560# '
66- # ' Main parameter arguments (and those in `...`) can avoid
67- # ' evaluation until the underlying function is executed by wrapping the
68- # ' argument in [rlang::expr()] (e.g. `mtry = expr(floor(sqrt(p)))`).
69- # '
7061# '
7162# ' @section Engine Details:
7263# '
7364# ' Engines may have pre-set default arguments when executing the
74- # ' model fit call. These can be changed by using the `...`
75- # ' argument to pass in the preferred values. For this type of
76- # ' model, the template of the fit calls are:
65+ # ' model fit call. For this type of model, the template of the
66+ # ' fit calls are:
7767# '
7868# ' \pkg{xgboost} classification
7969# '
10999# ' reloaded and reattached to the `parsnip` object.
110100# '
111101# ' @importFrom purrr map_lgl
112- # ' @seealso [varying()], [fit()]
102+ # ' @seealso [varying()], [fit()], [set_engine()]
113103# ' @examples
114104# ' boost_tree(mode = "classification", trees = 20)
115105# ' # Parameters can be represented by a placeholder:
@@ -121,11 +111,7 @@ boost_tree <-
121111 mtry = NULL , trees = NULL , min_n = NULL ,
122112 tree_depth = NULL , learn_rate = NULL ,
123113 loss_reduction = NULL ,
124- sample_size = NULL ,
125- ... ) {
126-
127- others <- enquos(... )
128-
114+ sample_size = NULL ) {
129115 args <- list (
130116 mtry = enquo(mtry ),
131117 trees = enquo(trees ),
@@ -136,18 +122,14 @@ boost_tree <-
136122 sample_size = enquo(sample_size )
137123 )
138124
139- if (! (mode %in% boost_tree_modes ))
140- stop(" `mode` should be one of: " ,
141- paste0(" '" , boost_tree_modes , " '" , collapse = " , " ),
142- call. = FALSE )
143-
144- no_value <- ! vapply(others , null_value , logical (1 ))
145- others <- others [no_value ]
146-
147- out <- list (args = args , others = others ,
148- mode = mode , method = NULL , engine = NULL )
149- class(out ) <- make_classes(" boost_tree" )
150- out
125+ new_model_spec(
126+ " boost_tree" ,
127+ args ,
128+ eng_args = NULL ,
129+ mode ,
130+ method = NULL ,
131+ engine = NULL
132+ )
151133 }
152134
153135# ' @export
@@ -167,6 +149,7 @@ print.boost_tree <- function(x, ...) {
167149# ' @export
168150# ' @inheritParams boost_tree
169151# ' @param object A boosted tree model specification.
152+ # ' @param ... Not used for `update`.
170153# ' @param fresh A logical for whether the arguments should be
171154# ' modified in-place of or replaced wholesale.
172155# ' @return An updated model specification.
@@ -183,10 +166,8 @@ update.boost_tree <-
183166 mtry = NULL , trees = NULL , min_n = NULL ,
184167 tree_depth = NULL , learn_rate = NULL ,
185168 loss_reduction = NULL , sample_size = NULL ,
186- fresh = FALSE ,
187- ... ) {
188-
189- others <- enquos(... )
169+ fresh = FALSE , ... ) {
170+ update_dot_check(... )
190171
191172 args <- list (
192173 mtry = enquo(mtry ),
@@ -209,23 +190,27 @@ update.boost_tree <-
209190 object $ args [names(args )] <- args
210191 }
211192
212- if (length( others ) > 0 ) {
213- if ( fresh )
214- object $ others <- others
215- else
216- object $ others [names( others )] <- others
217- }
218-
219- object
193+ new_model_spec(
194+ " boost_tree " ,
195+ args = object $ args ,
196+ eng_args = object $ eng_args ,
197+ mode = object $ mode ,
198+ method = NULL ,
199+ engine = object $ engine
200+ )
220201 }
221202
222203# ------------------------------------------------------------------------------
223204
224205# ' @export
225- translate.boost_tree <- function (x , engine , ... ) {
206+ translate.boost_tree <- function (x , engine = x $ engine , ... ) {
207+ if (is.null(engine )) {
208+ message(" Used `engine = 'xgboost'` for translation." )
209+ engine <- " xgboost"
210+ }
226211 x <- translate.default(x , engine , ... )
227212
228- if (x $ engine == " spark" ) {
213+ if (engine == " spark" ) {
229214 if (x $ mode == " unknown" )
230215 stop(
231216 " For spark boosted trees models, the mode cannot be 'unknown' " ,
0 commit comments