当我尝试用caret训练参数网格以进行训练时,我会遇到各种错误:
> 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的文档说:
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'.
并提供以下可正常工作的示例:
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
作为tuneLength
和train
的参数之间的联系是什么?它们可以len
和tuneLength
一起使用吗?他们的关系是什么?
如果它有帮助,这里有一个描述如何在createGrid
train
caret
中使用{{1}}的线程:caret::train: specify model-generation-parameters
答案 0 :(得分:1)
您从示例中提取的代码对我来说很好(并注意到它修复了您在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
我再说一遍:还有什么问题?