我正在尝试运行不需要参数的插入符方法,例如lda,下面的示例使用“lvq”,它需要2个参数(大小和k)
set.seed(7)
# load the library
library(caret)
# load the dataset
data(iris)
# prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)
# design the parameter tuning grid
grid <- expand.grid(size=c(5,10,20,50), k=c(1,2,3,4,5))
# train the model
model <- train(Species~., data=iris, method="lvq", trControl=control, tuneGrid=grid)
# summarize the model
print(model)
plot(model)
我尝试将其分配出tuneGrid = NULL
set.seed(7)
# load the library
library(caret)
# load the dataset
data(iris)
# prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)
# design the parameter tuning grid
grid <- expand.grid(size=c(5,10,20,50), k=c(1,2,3,4,5))
# train the model
model <- train(Species~., data=iris, method="lda", trControl=control, tuneGrid=NULL)
# summarize the model
print(model)
plot(model)
但是我收到了错误
There are no tuning parameters for this model
答案 0 :(得分:0)
我会回答我自己的问题,我认为只需删除tuneGrid=NULL
就可以了。
set.seed(7)
# load the library
library(caret)
# load the dataset
data(iris)
# prepare training scheme
control <- trainControl(method="repeatedcv", number=10, repeats=3)
# design the parameter tuning grid
grid <- expand.grid(size=c(5,10,20,50), k=c(1,2,3,4,5))
# train the model
model <- train(Species~., data=iris, method="lda", trControl=control)
# summarize the model
print(model)
答案 1 :(得分:0)
Caret包含许多LDA methods,如:
method =“ lda ”不涉及调整参数。 method =“ lda2 ”允许调整dimen(判别向量的数量)。
如果要调整参数(并且必须只是判别向量的数量),则必须使用“lda2”。 “lda”不允许调整以便运行它必须删除tuneGrid。删除tuneGrid只需关闭交叉验证。