首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无交叉验证的StepLDA

无交叉验证的StepLDA
EN

Stack Overflow用户
提问于 2015-08-22 18:53:49
回答 1查看 1.8K关注 0票数 1

我想根据训练误差来选择变量。因此,我在trainControl中将方法设置为"none“。但是,如果我在下面两次运行这个函数,就会得到两个不同的错误(正确率)。在这个例子中,差别是不值得提及的。即使如此,我也没想到会有什么不同。

有人知道这种差异是从何而来的吗?

代码语言:javascript
复制
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

第一个

代码语言:javascript
复制
`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 

第二位

代码语言:javascript
复制
> 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 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-22 19:42:44

你还在做十倍的交叉验证。只要你不设置种子,你就会得到一个稍微不同的答案,当你多次训练的模式。

如果您运行这段代码,包括set.seed,您将获得相同的正确率。

代码语言:javascript
复制
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是没有意义的。你会得到一堆警告和错误。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32159649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档