r - 使用 cv.glm(在引导包中)和 train(在插入符号包中)的不同结果
问题描述
我想使用 R 中逻辑回归模型的留一交叉验证来获得测试错误。
我使用两种方法做到了这一点。1) 在引导包中使用 cv.glm 2) 使用 caret 包
使用 cv.glm 的结果和代码如下,
require(ISLR)
require(boot)
require(caret)
str(Smarket)
fit1 <- glm(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,
family = binomial, data = Smarket)
cv.glm(Smarket,fit1)$delta
> cv.glm(Smarket,fit1)$delta
[1] 0.2518003 0.2517992
所以遗漏交叉验证误差约为 0.25
然后我使用了 caret 包。结果和使用插入符号的代码如下,
fitControlcv <- trainControl( method = "LOOCV")
mod_fit <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,
data=Smarket, method="glm", family="binomial",
trControl = fitControlcv)
mod_fit
> mod_fit
Generalized Linear Model
1250 samples
6 predictor
2 classes: 'Down', 'Up'
No pre-processing
Resampling: Leave-One-Out Cross-Validation
Summary of sample sizes: 1249, 1249, 1249, 1249, 1249, 1249, ...
Resampling results:
Accuracy Kappa
0.4976 -0.02588095
在这种情况下,留一法交叉验证测试错误率约为 0.50 (1-0.4976)
我使用不同的软件包得到不同答案的原因可能是什么?
我在这里做错了吗?
如果有人可以帮助我,我真的很感激
解决方案
推荐阅读
- promise - How to get rid of 'return new Promise' and not to lose data?
- kerberos - oozie-hive 直线不适用于 kerberos
- excel - 基于标准的 Excel 索引
- string - 命令行如何将字符串搜索到 %% 变量中
- python - 可以从 IDE 运行 selenium 脚本,但不能从 cmd
- database - 如何修复“数据库错误:前端与 Zabbix 数据库不匹配”。
- php - 如何通过特定数字和数据输入来制作唯一标识符
- javascript - 从多个表格的列表中选择下一个数字
- android - 如何控制谁可以从 Play 商店安装我的应用程序?
- sql-server - SQL Server 数据库还原非常慢 (FILESTREAM)