【问题标题】:run caret method without parameters运行不带参数的插入符方法
【发布时间】:2017-04-06 13:40:58
【问题描述】:

我正在尝试运行不需要参数的插入符号方法,例如 lda,下面的示例使用需要 2 个参数(大小和 k)的“lvq”

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

【问题讨论】:

  • 您正在打印lda,但您将结果分配给lda2。似乎这只是一个错字。但在寻求帮助时,请确保包含包含示例数据的reproducible example。我们无法运行此代码来查看问题所在,因为我们的计算机上不存在该输入文件。

标签: r r-caret


【解决方案1】:

插入符号包含多个 LDA methods 像:

method = "lda" 不涉及调整参数。 method = "lda2" 允许调整维度(判别向量的数量)。

如果你想调整参数(并且必须是判别向量的数量),你必须使用“lda2”。 “lda”不允许调整,因此要运行它,您必须删除 tuneGrid。删除 tuneGrid 你只需关闭交叉验证。

【讨论】:

    【解决方案2】:

    我会回答我自己的问题,我认为只需删除 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多