r - caret::train: 指定模型生成参数

标签 r r-caret

我正在使用 caret R中的库用于模型生成。我想生成一个 earth (又名 MARS)模型,我想指定 degree此模型生成的参数。根据documentation (第 11 页) earth方法支持此参数。

指定参数时,我收到以下错误消息:

> library(caret)
> data(trees)
> train(Volume~Girth+Height, data=trees, method='earth', degree=1)
Error in { : 
  task 1 failed - "formal argument "degree" matched by multiple actual arguments"

指定 degree 时如何避免此错误范围?
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] earth_3.2-3    plotrix_3.4    plotmo_1.3-1   leaps_2.9      caret_5.15-023
 [6] foreach_1.4.0  cluster_1.14.2 reshape_0.8.4  plyr_1.7.1     lattice_0.20-6

loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_2.15.0 grid_2.15.0     iterators_1.0.6
[5] tools_2.15.0   

最佳答案

我一直在中找到功能插入符号 既有用又有些令人抓狂。这是发生了什么。

您正试图将参数传递给 earth通过 ...论据 train . train 的文档包含该参数的描述:

arguments passed to the classification or regression routine (such as randomForest). Errors will occur if values for tuning parameters are passed here.



调整参数,嗯?好吧,如果您向下滚动并检查每种模型类型的官方调整参数列表,您会看到 earth , 他们是 degreenprune .

所以这里的问题是 train旨在根据调整参数自动进行一些网格搜索,而 ...参数用于将更多参数传递给模型拟合函数,除了那些调整参数。

如果要设置调整参数,则需要使用其他参数,如下所示:
train(Volume~Girth+Height, data=trees, method='earth',
      tuneGrid = data.frame(.degree = 1,.nprune = 5))

请注意列是如何用前导句点命名的。此外,令人沮丧的是,由于 earth 中的默认值为 npruneNULL ,我不确定您是否只能以这种方式传递默认值。 (通常,在数据框中将东西设置为 NULL 只会简单地删除它们。)

关于r - caret::train: 指定模型生成参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10498477/

相关文章:

r - 如何通过 R 调用 Stata 并运行语法?

r - 按频率/值排序离散 x 比例

r - R编程-将时间范围设置为今天

r - caretEnsemble 错误 : Error in FUN(X[[i]], ...) : { . ... 不是 TRUE

r - 使用插入符号库修剪树返回复杂的树

r - 插入符号中的并行执行列车失败,未找到函数

多核中的R caret nnet软件包

r - 如何从R中的向量创建边缘列表

r - R中同时使用两列的聚合函数

r - 错误: nrow(x) == n is not TRUE when using Train in Caret