1

I'm trying to run a caret method that not requires parameters, such as lda, the example below uses "lvq" which needs 2 parameters (size and 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)

I tried to work it out assigning 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)

But I get the error

There are no tuning parameters for this model
user3437823
  • 351
  • 2
  • 14
  • You are printing `lda` but you assigned the results to `lda2`. Seems like this is just a typo. But when asking for help make sure to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that includes sample data. We can't run this code to see what's wrong because that input file doesn't exist on our computers. – MrFlick Apr 06 '17 at 13:55

2 Answers2

1

Caret contains a number of LDA methods like:

method = "lda" involves no tuning parameters. method = "lda2" allows to tune dimen (number of discriminant vectors).

If you want to tune parameters (and that must be only number of discriminant vectors), you must use "lda2". "lda" do not allows tuning so to run it you must delete tuneGrid. Deleting tuneGrid you just switch off cross-validation.

Katin
  • 177
  • 1
  • 13
0

I'll answer my own question, I think that just deleting the tuneGrid=NULL works fine

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)
user3437823
  • 351
  • 2
  • 14