我想根据训练误差来选择变量。因此,我在trainControl中将方法设置为"none“。但是,如果我在下面两次运行这个函数,就会得到两个不同的错误(正确率)。在这个例子中,差别是不值得提及的。即使如此,我也没想到会有什么不同。
有人知道这种差异是从何而来的吗?
library(caret)
c_1 <- trainControl(method = "none")
maxvar <-(4)
direction <-"forward"
tune_1 <-data.frame(maxvar,direction)
train(Species~., data=iris, method = "stepLDA", trControl=c_1, tuneGrid=tune_1)->tr第一个
`stepwise classification', using 10-fold cross-validated correctness rate of method lda'.
150 observations of 4 variables in 3 classes; direction: forward
stop criterion: assemble 4 best variables.
correctness rate: 0.96; in: "Petal.Width"; variables (1): Petal.Width
correctness rate: 0.96667; in: "Sepal.Width"; variables (2): Petal.Width, Sepal.Width
correctness rate: 0.97333; in: "Petal.Length"; variables (3): Petal.Width, Sepal.Width, Petal.Length
correctness rate: 0.98; in: "Sepal.Length"; variables (4): Petal.Width, Sepal.Width, Petal.Length, Sepal.Length
hr.elapsed min.elapsed sec.elapsed
0.00 0.00 0.28 第二位
> train(Species~., data=iris, method = "stepLDA", trControl=c_1, tuneGrid=tune_1)->tr
`stepwise classification', using 10-fold cross-validated correctness rate of method lda'.
150 observations of 4 variables in 3 classes; direction: forward
stop criterion: assemble 4 best variables.
correctness rate: 0.96; in: "Petal.Width"; variables (1): Petal.Width
correctness rate: 0.96; in: "Sepal.Width"; variables (2): Petal.Width, Sepal.Width
correctness rate: 0.96667; in: "Petal.Length"; variables (3): Petal.Width, Sepal.Width, Petal.Length
correctness rate: 0.98; in: "Sepal.Length"; variables (4): Petal.Width, Sepal.Width, Petal.Length, Sepal.Length
hr.elapsed min.elapsed sec.elapsed
0.0 0.0 0.3 发布于 2015-08-22 19:42:44
你还在做十倍的交叉验证。只要你不设置种子,你就会得到一个稍微不同的答案,当你多次训练的模式。
如果您运行这段代码,包括set.seed,您将获得相同的正确率。
set.seed(42)
tr <- train(Species~., data=iris, method = "stepLDA", trControl=c_1, tuneGrid=tune_1)根据评论编辑:
10倍交叉验证的正确率不是来自卡雷特,而是来自klaR包中的逐步类函数。
逐步类(x,分组,方法,改进= 0.05,maxvar = Inf,start.vars = NULL,方向=c(“两者”,“前进”,“向后”),准则= "CR",折叠= 10,cv.groups =空,输出=真,min1var =真,. 用于交叉验证的折叠参数;如果指定了“cv.groups”,则省略。
如果您愿意,只需在列车函数中添加折叠参数,就可以调整这一点:
tr <- train(Species~., data=iris, method = "stepLDA", trControl=c_1, tuneGrid=tune_1, fold = 1)
但是一倍的1是没有意义的。你会得到一堆警告和错误。
https://stackoverflow.com/questions/32159649
复制相似问题