关于R中的插入符号包,当应用K折叠交叉验证时

关于R中的插入符号包,当应用K折叠交叉验证时,r,cross-validation,r-caret,R,Cross Validation,R Caret,我使用R中的caret软件包拟合了一个逻辑回归模型(使用ISLR软件包中的Smarket数据集)。然后,我使用(总体测试误差)K倍交叉验证(K=5)计算了总未分类误差,如下所示: require(ISLR) require(caret) fitControl <- trainControl(method = "cv",number = 5) mod_fit <- train(Direction ~ Lag1 + Lag2 + Lag3 + Lag4 + Lag5 + Volume,

我使用R中的caret软件包拟合了一个逻辑回归模型(使用ISLR软件包中的Smarket数据集)。然后,我使用(总体测试误差)K倍交叉验证(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
table((mod_fit$pred)$obs,(mod_fit$pred)$pred)
      Down  Up
  Down  125 477
  Up    151 497
require(ISLR)
需要(插入符号)

fitControl可通过将观察值和预测值交叉制表,如下所示:

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
table((mod_fit$pred)$obs,(mod_fit$pred)$pred)
      Down  Up
  Down  125 477
  Up    151 497
所以

你试过使用吗

confusionMatrix(data = predictions, reference = observations)

应该给你你想要的和更多。您还可以查看更多详细信息。

您访问过吗?据我所知,如果您使用k折叠交叉验证,这将不会直接起作用。