关于应用 K 折交叉验证时 R 中的 Caret 包
Regarding the Caret package in R when apply K fold cross validation
我已经使用 R 中的 caret 包拟合了一个逻辑回归模型(使用 ISLR 包中的 Smarket 数据集)。然后我使用(总体测试误差)K 折交叉计算了总的未命中class化错误验证(K=5)如下,
require(ISLR)
require(caret)
fitControl <- trainControl(method = "cv",number = 5)
mod_fit <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,
data=Smarket, method="glm",trControl = fitControlcv)
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
根据上面的输出,我能够计算出总未命中 class化错误,因为,
总失误 classification=1- 准确性。
有没有办法使用 K 折交叉验证从插入符号包中提取灵敏度和特异性(class 特定错误)?
我能够通过创建一个用户定义的函数来计算 K 折交叉验证中的灵敏度和特异性:https://youtu.be/AFg2MvhFeho
但我想知道是否可以使用 caret 包轻松完成。
谢谢
可以通过如下交叉制表观察值和预测值来完成,
table((mod_fit$pred)$obs,(mod_fit$pred)$pred)
Down Up
Down 125 477
Up 151 497
所以
overall missclassification = (125+497)/250 = 0.4976
sensitivity = 497/(151+497) = 0.7770
您尝试过使用
confusionMatrix(data = predictions, reference = observations)
应该能为您提供所需的内容以及更多内容。您还可以查看更多详细信息 here.
我已经使用 R 中的 caret 包拟合了一个逻辑回归模型(使用 ISLR 包中的 Smarket 数据集)。然后我使用(总体测试误差)K 折交叉计算了总的未命中class化错误验证(K=5)如下,
require(ISLR)
require(caret)
fitControl <- trainControl(method = "cv",number = 5)
mod_fit <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,
data=Smarket, method="glm",trControl = fitControlcv)
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
根据上面的输出,我能够计算出总未命中 class化错误,因为,
总失误 classification=1- 准确性。
有没有办法使用 K 折交叉验证从插入符号包中提取灵敏度和特异性(class 特定错误)?
我能够通过创建一个用户定义的函数来计算 K 折交叉验证中的灵敏度和特异性:https://youtu.be/AFg2MvhFeho
但我想知道是否可以使用 caret 包轻松完成。
谢谢
可以通过如下交叉制表观察值和预测值来完成,
table((mod_fit$pred)$obs,(mod_fit$pred)$pred)
Down Up
Down 125 477
Up 151 497
所以
overall missclassification = (125+497)/250 = 0.4976
sensitivity = 497/(151+497) = 0.7770
您尝试过使用
confusionMatrix(data = predictions, reference = observations)
应该能为您提供所需的内容以及更多内容。您还可以查看更多详细信息 here.