使用插入符号时,rf (randomForest) 的 createGrid 错误 [英] Errors with createGrid for rf (randomForest) when using caret
问题描述
当我尝试使用 caret 创建用于训练的参数网格时,我得到各种错误:
When I try to crate a grid of parameters for training with caret I get various errors:
> my_grid <- createGrid("rf")
Error in if (p <= len) { : argument is of length zero
> my_grid <- createGrid("rf", 4)
Error in if (p <= len) { : argument is of length zero
> my_grid <- createGrid("rf", len=4)
Error in if (p <= len) { : argument is of length zero
createGrid 的文档说:
The documentation for createGrid says:
This function creates a data frame that contains a grid of
complexity parameters specific methods.
Usage:
createGrid(method, len = 3, data = NULL)
Arguments:
method: a string specifying which classification model to use. See
'train' for a full list.
len: an integer specifying the number of points on the grid for
each tuning parameter.
data: the training data (only needed in the case where the 'method'
is 'cforest', 'earth', 'bagEarth', 'fda', 'bagFDA', 'rpart',
'svmRadial', 'pam', 'lars2', 'rf' or 'pls'). The outcome
should be in a column called '.outcome'.
并给出以下正确工作的例子:
and gives the following examples which work correctly:
createGrid("rda", 4)
createGrid("lm")
createGrid("nnet")
## data needed for SVM with RBF:
## Not run:
tmp <- iris
names(tmp)[5] <- ".outcome"
head(tmp)
createGrid("svmRadial", data = tmp, len = 4)
## End(Not run)
这样,我做错了什么?
len
作为 createGrid
的参数和 train
的参数中的 tuneLength
之间有什么联系?len
和 tuneLength
可以一起使用吗?他们是什么关系?
What is the connection between len
as an argument to createGrid
and tuneLength
in the argument for train
? Can len
and tuneLength
they be used together? What is their relationship?
如果有帮助,这里有一个线程描述如何在 caret
中使用 createGrid
和 train
:caret::train:指定模型生成参数
In case it helps, here is a thread describing how to use createGrid
with train
in caret
: caret::train: specify model-generation-parameters
推荐答案
您从示例中提取的代码对我来说很好用(并注意到它修复了您在 Rhelp 上发布时存在的问题):
The code you pulled from the examples works fine for me (and noting that it fixes the problem that existed when you posted on Rhelp):
tmp <- iris
names(tmp)[5] <- ".outcome"
head(tmp)
createGrid("svmRadial", data = tmp, len = 4)
#-------
.sigma .C
1 0.7500934 0.25
2 0.7500934 0.50
3 0.7500934 1.00
4 0.7500934 2.00
> createGrid("rf", data = tmp, len = 4)
randomForest 4.6-7
Type rfNews() to see new features/changes/bug fixes.
Attaching package: ‘randomForest’
The following object(s) are masked from ‘package:Hmisc’:
combine
note: only 3 unique complexity parameters in default grid. Truncating the grid to 3 .
.mtry
1 2
2 3
3 4
我再说一遍:还有什么问题?
I say again: What problem remains?
这篇关于使用插入符号时,rf (randomForest) 的 createGrid 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!