当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R parsnip parsnip_update 更新型号规格


如果需要修改模型规范的参数,可以使用update()代替从头开始重新创建对象。

用法

# S3 method for bag_mars
update(
  object,
  parameters = NULL,
  num_terms = NULL,
  prod_degree = NULL,
  prune_method = NULL,
  fresh = FALSE,
  ...
)

# S3 method for bag_mlp
update(
  object,
  parameters = NULL,
  hidden_units = NULL,
  penalty = NULL,
  epochs = NULL,
  fresh = FALSE,
  ...
)

# S3 method for bag_tree
update(
  object,
  parameters = NULL,
  cost_complexity = NULL,
  tree_depth = NULL,
  min_n = NULL,
  class_cost = NULL,
  fresh = FALSE,
  ...
)

# S3 method for bart
update(
  object,
  parameters = NULL,
  trees = NULL,
  prior_terminal_node_coef = NULL,
  prior_terminal_node_expo = NULL,
  prior_outcome_range = NULL,
  fresh = FALSE,
  ...
)

# 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 C5_rules
update(
  object,
  parameters = NULL,
  trees = NULL,
  min_n = NULL,
  fresh = FALSE,
  ...
)

# S3 method for cubist_rules
update(
  object,
  parameters = NULL,
  committees = NULL,
  neighbors = NULL,
  max_rules = 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 discrim_flexible
update(
  object,
  num_terms = NULL,
  prod_degree = NULL,
  prune_method = NULL,
  fresh = FALSE,
  ...
)

# S3 method for discrim_linear
update(
  object,
  penalty = NULL,
  regularization_method = NULL,
  fresh = FALSE,
  ...
)

# S3 method for discrim_quad
update(object, regularization_method = NULL, fresh = FALSE, ...)

# S3 method for discrim_regularized
update(
  object,
  frac_common_cov = NULL,
  frac_identity = NULL,
  fresh = FALSE,
  ...
)

# S3 method for gen_additive_mod
update(
  object,
  select_features = NULL,
  adjust_deg_free = NULL,
  parameters = 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,
  learn_rate = NULL,
  fresh = FALSE,
  ...
)

# S3 method for multinom_reg
update(
  object,
  parameters = NULL,
  penalty = NULL,
  mixture = NULL,
  fresh = FALSE,
  ...
)

# S3 method for naive_Bayes
update(object, smoothness = NULL, Laplace = 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 pls
update(
  object,
  parameters = NULL,
  predictor_prop = NULL,
  num_comp = NULL,
  fresh = FALSE,
  ...
)

# S3 method for poisson_reg
update(
  object,
  parameters = NULL,
  penalty = NULL,
  mixture = 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 rule_fit
update(
  object,
  parameters = NULL,
  mtry = NULL,
  trees = NULL,
  min_n = NULL,
  tree_depth = NULL,
  learn_rate = NULL,
  loss_reduction = NULL,
  sample_size = NULL,
  penalty = 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,
  ...
)

参数

object

型号规格。

parameters

包含要更新的主要参数的 1 行 tibble 或命名列表。更新时直接使用parameters 或主要参数。如果使用主要参数,这些参数将取代 parameters 中的值。此外,在此对象中使用引擎参数将导致错误。

num_terms

最终模型中将保留的特征数量,包括截距。

prod_degree

尽可能高的交互程度。

prune_method

修剪方法。

fresh

是否应该就地修改参数或批量替换参数的逻辑。

...

不用于update()

hidden_units

隐藏模型中单元数量的整数。

penalty

一个非负数,表示某些引擎使用的正则化量。

epochs

训练迭代次数的整数。

cost_complexity

CART 模型(仅限特定引擎)使用的成本/复杂性参数(也称为 Cp )的正数。

tree_depth

树的最大深度的整数。

min_n

节点中进一步拆分节点所需的最小数据点数量的整数。

class_cost

类成本的非负标量(其中成本为 1 意味着没有额外成本)。当结果因子的第一级是少数群体时,这非常有用。如果不是这种情况,则可以使用零到一之间的值来偏置到因子的第二级。

trees

集合中包含的树数的整数。

prior_terminal_node_coef

节点是终端节点的先验概率的系数。

prior_terminal_node_expo

节点是终端节点的先验概率的指数。

prior_outcome_range

一个正值,定义预测结果在一定范围内的先验宽度。对于回归来说,它与观察到的数据范围有关;先验是由数据观测范围定义的高斯分布的标准差数。对于分类,它被定义为+/-3的范围(假设在logit标度上)。默认值为 2。

mtry

创建树模型时将在每次分割时随机采样的预测变量的数量(或比例)的数字(仅限特定引擎)

learn_rate

提升算法从迭代到迭代的适应速率的数字(仅限特定引擎)。这有时称为收缩参数。

loss_reduction

进一步分割所需的损失函数减少的数字(仅限特定引擎)。

sample_size

一个数字,表示暴露给拟合例程的数据数量(或比例)。对于 xgboost ,在每次迭代时进行采样,而 C5.0 在训练期间采样一次。

stop_iter

停止前没有改进的迭代次数(仅限特定引擎)。

committees

集合成员数量的非负整数(不大于 100)。

neighbors

用于调整基于模型的预测的训练集实例数量的 0 到 9 之间的整数。

max_rules

规则数量最多。

regularization_method

正则化估计类型的字符串。可能的值为:“diagonal”、“min_distance”、“shrink_cov”和“shrink_mean”(仅限 sparsediscrim 引擎)。

frac_common_cov, frac_identity

零到一之间的数值。

select_features

TRUEFALSE. 如果是 TRUE ,则模型有能力消除预测变量(通过惩罚)。增加 adjust_deg_free 将增加删除预测变量的可能性。

adjust_deg_free

如果是 select_features = TRUE ,则充当平滑度的乘数。将此值增加到 1 以上以生成更平滑的模型。

mixture

0 到 1(含)之间的数字,表示模型中 L1 正则化(即 lasso)的比例。

  • mixture = 1指定纯套索模型,

  • mixture = 0 指定岭回归模型,并且

  • 0 < mixture < 1 指定弹性网络模型,插值套索和岭。

仅适用于特定发动机。

dropout

0(含)到 1 之间的数字,表示模型训练期间随机设置为零的模型参数的比例。

activation

表示原始预测变量和隐藏单元层之间关系类型的单个字符串。隐藏层和输出层之间的激活函数根据结果类型自动设置为 "linear" 或 "softmax"。可能的值为:"linear"、"softmax"、"relu" 和 "elu"

smoothness

一个非负数,表示类边界的相对平滑度。较小的示例会导致模型灵活的边界,较大的值会生成适应性较差的类边界

Laplace

用于平滑 low-frequency 计数的拉普拉斯校正的非负值。

weight_func

用于对样本之间的距离进行加权的核函数类型的单个字符。有效的选择是: "rectangular" , "triangular" , "epanechnikov" , "biweight" , "triweight" , "cos" , "inv" , "gaussian" , "rank""optimal"

dist_power

用于计算 Minkowski 距离的参数的单个数字。

predictor_prop

每个 PLS 分量可以具有非零系数的原始预测变量的最大比例(通过正则化)。该值用于 X 的所有 PLS 分量。

num_comp

要保留的 PLS 组件的数量。

dist

结果概率分布的字符串。默认为"weibull"。

cost

预测样本在边以内或错误一侧的成本的正数

margin

SVM 不敏感损失函数中 epsilon 的正数(仅回归)

degree

多项式次数为正数。

scale_factor

多项式比例因子的正数。

rbf_sigma

径向基函数的正数。

更新的模型规格。

例子


# ------------------------------------------------------------------------------

model <- C5_rules(trees = 10, min_n = 2)
model
#> ! parsnip could not locate an implementation for `C5_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> C5.0 Model Specification (classification)
#> 
#> Main Arguments:
#>   trees = 10
#>   min_n = 2
#> 
#> Computational engine: C5.0 
#> 
update(model, trees = 1)
#> ! parsnip could not locate an implementation for `C5_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> C5.0 Model Specification (classification)
#> 
#> Main Arguments:
#>   trees = 1
#>   min_n = 2
#> 
#> Computational engine: C5.0 
#> 
update(model, trees = 1, fresh = TRUE)
#> ! parsnip could not locate an implementation for `C5_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> C5.0 Model Specification (classification)
#> 
#> Main Arguments:
#>   trees = 1
#> 
#> Computational engine: C5.0 
#> 

# ------------------------------------------------------------------------------

model <- cubist_rules(committees = 10, neighbors = 2)
model
#> ! parsnip could not locate an implementation for `cubist_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> Cubist Model Specification (regression)
#> 
#> Main Arguments:
#>   committees = 10
#>   neighbors = 2
#> 
#> Computational engine: Cubist 
#> 
update(model, committees = 1)
#> ! parsnip could not locate an implementation for `cubist_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> Cubist Model Specification (regression)
#> 
#> Main Arguments:
#>   committees = 1
#>   neighbors = 2
#> 
#> Computational engine: Cubist 
#> 
update(model, committees = 1, fresh = TRUE)
#> ! parsnip could not locate an implementation for `cubist_rules` model
#>   specifications.
#> ℹ The parsnip extension package rules implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> Cubist Model Specification (regression)
#> 
#> Main Arguments:
#>   committees = 1
#> 
#> Computational engine: Cubist 
#> 
model <- pls(predictor_prop =  0.1)
model
#> ! parsnip could not locate an implementation for `pls` model
#>   specifications.
#> ℹ The parsnip extension package plsmod implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> PLS Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   predictor_prop = 0.1
#> 
#> Computational engine: mixOmics 
#> 
update(model, predictor_prop = 1)
#> ! parsnip could not locate an implementation for `pls` model
#>   specifications.
#> ℹ The parsnip extension package plsmod implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> PLS Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   predictor_prop = 1
#> 
#> Computational engine: mixOmics 
#> 
update(model, predictor_prop = 1, fresh = TRUE)
#> ! parsnip could not locate an implementation for `pls` model
#>   specifications.
#> ℹ The parsnip extension package plsmod implements support for this
#>   specification.
#> ℹ Please install (if needed) and load to continue.
#> PLS Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   predictor_prop = 1
#> 
#> Computational engine: mixOmics 
#> 
# ------------------------------------------------------------------------------

model <- rule_fit(trees = 10, min_n = 2)
model
#> ! parsnip could not locate an implementation for `rule_fit` model
#>   specifications.
#> ℹ The parsnip extension packages agua and rules implement support for
#>   this specification.
#> ℹ Please install (if needed) and load to continue.
#> RuleFit Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   trees = 10
#>   min_n = 2
#> 
#> Computational engine: xrf 
#> 
update(model, trees = 1)
#> ! parsnip could not locate an implementation for `rule_fit` model
#>   specifications.
#> ℹ The parsnip extension packages agua and rules implement support for
#>   this specification.
#> ℹ Please install (if needed) and load to continue.
#> RuleFit Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   trees = 1
#>   min_n = 2
#> 
#> Computational engine: xrf 
#> 
update(model, trees = 1, fresh = TRUE)
#> ! parsnip could not locate an implementation for `rule_fit` model
#>   specifications.
#> ℹ The parsnip extension packages agua and rules implement support for
#>   this specification.
#> ℹ Please install (if needed) and load to continue.
#> RuleFit Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   trees = 1
#> 
#> Computational engine: xrf 
#> 
model <- boost_tree(mtry = 10, min_n = 3)
model
#> Boosted Tree Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   mtry = 10
#>   min_n = 3
#> 
#> Computational engine: xgboost 
#> 
update(model, mtry = 1)
#> Boosted Tree Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   mtry = 1
#>   min_n = 3
#> 
#> Computational engine: xgboost 
#> 
update(model, mtry = 1, fresh = TRUE)
#> Boosted Tree Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   mtry = 1
#> 
#> Computational engine: xgboost 
#> 

param_values <- tibble::tibble(mtry = 10, tree_depth = 5)

model %>% update(param_values)
#> Boosted Tree Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   mtry = 10
#>   min_n = 3
#>   tree_depth = 5
#> 
#> Computational engine: xgboost 
#> 
model %>% update(param_values, mtry = 3)
#> Boosted Tree Model Specification (unknown mode)
#> 
#> Main Arguments:
#>   mtry = 10
#>   min_n = 3
#>   tree_depth = 5
#> 
#> Computational engine: xgboost 
#> 

param_values$verbose <- 0
# Fails due to engine argument
# model %>% update(param_values)

model <- linear_reg(penalty = 10, mixture = 0.1)
model
#> Linear Regression Model Specification (regression)
#> 
#> Main Arguments:
#>   penalty = 10
#>   mixture = 0.1
#> 
#> Computational engine: lm 
#> 
update(model, penalty = 1)
#> Linear Regression Model Specification (regression)
#> 
#> Main Arguments:
#>   penalty = 1
#>   mixture = 0.1
#> 
#> Computational engine: lm 
#> 
update(model, penalty = 1, fresh = TRUE)
#> Linear Regression Model Specification (regression)
#> 
#> Main Arguments:
#>   penalty = 1
#> 
#> Computational engine: lm 
#> 

相关用法


注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Updating a model specification。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。