If parameters of a model specification need to be modified, update()
can
be used in lieu of recreating the object from scratch.
# S3 method for boost_tree
update(
object,
parameters = NULL,
mtry = NULL,
trees = NULL,
min_n = NULL,
tree_depth = NULL,
learn_rate = NULL,
loss_reduction = NULL,
sample_size = NULL,
stop_iter = NULL,
fresh = FALSE,
...
)# S3 method for decision_tree
update(
object,
parameters = NULL,
cost_complexity = NULL,
tree_depth = NULL,
min_n = NULL,
fresh = FALSE,
...
)
# S3 method for linear_reg
update(
object,
parameters = NULL,
penalty = NULL,
mixture = NULL,
fresh = FALSE,
...
)
# S3 method for logistic_reg
update(
object,
parameters = NULL,
penalty = NULL,
mixture = NULL,
fresh = FALSE,
...
)
# S3 method for mars
update(
object,
parameters = NULL,
num_terms = NULL,
prod_degree = NULL,
prune_method = NULL,
fresh = FALSE,
...
)
# S3 method for mlp
update(
object,
parameters = NULL,
hidden_units = NULL,
penalty = NULL,
dropout = NULL,
epochs = NULL,
activation = NULL,
fresh = FALSE,
...
)
# S3 method for multinom_reg
update(
object,
parameters = NULL,
penalty = NULL,
mixture = NULL,
fresh = FALSE,
...
)
# S3 method for nearest_neighbor
update(
object,
parameters = NULL,
neighbors = NULL,
weight_func = NULL,
dist_power = NULL,
fresh = FALSE,
...
)
# S3 method for proportional_hazards
update(
object,
parameters = NULL,
penalty = NULL,
mixture = NULL,
fresh = FALSE,
...
)
# S3 method for rand_forest
update(
object,
parameters = NULL,
mtry = NULL,
trees = NULL,
min_n = NULL,
fresh = FALSE,
...
)
# S3 method for surv_reg
update(object, parameters = NULL, dist = NULL, fresh = FALSE, ...)
# S3 method for survival_reg
update(object, parameters = NULL, dist = NULL, fresh = FALSE, ...)
# S3 method for svm_linear
update(
object,
parameters = NULL,
cost = NULL,
margin = NULL,
fresh = FALSE,
...
)
# S3 method for svm_poly
update(
object,
parameters = NULL,
cost = NULL,
degree = NULL,
scale_factor = NULL,
margin = NULL,
fresh = FALSE,
...
)
# S3 method for svm_rbf
update(
object,
parameters = NULL,
cost = NULL,
rbf_sigma = NULL,
margin = NULL,
fresh = FALSE,
...
)
A model specification.
A 1-row tibble or named list with main
parameters to update. Use either parameters
or the main arguments
directly when updating. If the main arguments are used,
these will supersede the values in parameters
. Also, using
engine arguments in this object will result in an error.
A number for the number (or proportion) of predictors that will
be randomly sampled at each split when creating the tree models (xgboost
only).
An integer for the number of trees contained in the ensemble.
An integer for the minimum number of data points in a node that is required for the node to be split further.
An integer for the maximum depth of the tree (i.e. number
of splits) (xgboost
only).
A number for the rate at which the boosting algorithm adapts
from iteration-to-iteration (xgboost
only).
A number for the reduction in the loss function required
to split further (xgboost
only).
A number for the number (or proportion) of data that is
exposed to the fitting routine. For xgboost
, the sampling is done at
each iteration while C5.0
samples once during training.
The number of iterations without improvement before
stopping (xgboost
only).
A logical for whether the arguments should be modified in-place or replaced wholesale.
Not used for update()
.
A positive number for the the cost/complexity
parameter (a.k.a. Cp
) used by CART models (rpart
only).
A non-negative number representing the total
amount of regularization (glmnet
, keras
, and spark
only).
For keras
models, this corresponds to purely L2 regularization
(aka weight decay) while the other models can be a combination
of L1 and L2 (depending on the value of mixture
; see below).
A number between zero and one (inclusive) that is the
proportion of L1 regularization (i.e. lasso) in the model. When
mixture = 1
, it is a pure lasso model while mixture = 0
indicates that
ridge regression is being used. (glmnet
and spark
only).
The number of features that will be retained in the final model, including the intercept.
The highest possible interaction degree.
The pruning method.
An integer for the number of units in the hidden model.
A number between 0 (inclusive) and 1 denoting the proportion of model parameters randomly set to zero during model training.
An integer for the number of training iterations.
A single character string denoting the type of relationship between the original predictors and the hidden unit layer. The activation function between the hidden and output layers is automatically set to either "linear" or "softmax" depending on the type of outcome. Possible values are: "linear", "softmax", "relu", and "elu"
A single integer for the number of neighbors
to consider (often called k
). For kknn, a value of 5
is used if neighbors
is not specified.
A single character for the type of kernel function used
to weight distances between samples. Valid choices are: "rectangular"
,
"triangular"
, "epanechnikov"
, "biweight"
, "triweight"
,
"cos"
, "inv"
, "gaussian"
, "rank"
, or "optimal"
.
A single number for the parameter used in calculating Minkowski distance.
A character string for the outcome distribution. "weibull" is the default.
A positive number for the cost of predicting a sample within or on the wrong side of the margin
A positive number for the epsilon in the SVM insensitive loss function (regression only)
A positive number for polynomial degree.
A positive number for the polynomial scaling factor.
A positive number for radial basis function.
An updated model specification.
# NOT RUN {
model <- boost_tree(mtry = 10, min_n = 3)
model
update(model, mtry = 1)
update(model, mtry = 1, fresh = TRUE)
param_values <- tibble::tibble(mtry = 10, tree_depth = 5)
model %>% update(param_values)
model %>% update(param_values, mtry = 3)
param_values$verbose <- 0
# Fails due to engine argument
# model %>% update(param_values)
model <- linear_reg(penalty = 10, mixture = 0.1)
model
update(model, penalty = 1)
update(model, penalty = 1, fresh = TRUE)
# }
Run the code above in your browser using DataLab