R 模型选择是否使用交叉验证?

R 模型选择是否使用交叉验证?,r,machine-learning,cross-validation,r-caret,k-fold,R,Machine Learning,Cross Validation,R Caret,K Fold,所以我开始有点困惑了。例如,具有以下培训GLM模型的代码: glm_sens = train( form = target ~ ., data = ABT, trControl = trainControl(method = "repeatedcv", number = 5, repeats = 10, classProbs = TRUE, summaryFunction = twoClassSummary, savePredictions = TRUE), method = "

所以我开始有点困惑了。例如,具有以下培训GLM模型的代码:

glm_sens = train(
  form = target ~ .,
  data = ABT,
  trControl = trainControl(method = "repeatedcv", number = 5, repeats = 10, classProbs = TRUE, summaryFunction = twoClassSummary, savePredictions = TRUE),
  method = "glm",
  family = "binomial",
  metric = "Sens"
)
我希望这会训练一些模型,然后选择一个在灵敏度方面表现最好的模型。然而,当我阅读交叉验证时,我发现大多数是关于如何使用交叉验证计算平均绩效分数


我的假设错了吗?

插入符号确实训练不同的模型,但通常使用不同的超参数。你可以查看一个。超参数无法直接从数据中学习,因此需要进行培训。这些参数决定了模型的行为方式,例如lasso中的lambda决定了对模型应用了多少正则化

在glm中,没有要训练的超参数。我想你要找的是从许多潜在变量中选择最好的线性模型。您可以使用步骤()

另一种选择是使用带插入符号的跳跃,例如,上述等效项为:

train(mpg~ .,data=mtcars,method='leapBackward', trControl=trainControl(method="cv",number=10),tuneGrid=data.frame(nvmax=2:6)) 

Linear Regression with Backwards Selection 

32 samples
10 predictors

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 30, 28, 28, 28, 30, 28, ... 
Resampling results across tuning parameters:

  nvmax  RMSE      Rsquared   MAE     
  2      3.299712  0.9169529  2.783068
  3      3.124146  0.8895539  2.750305
  4      3.249803  0.8849213  2.853777
  5      3.258143  0.8939493  2.823721
  6      3.123481  0.8917197  2.723475

RMSE was used to select the optimal model using the smallest value.
The final value used for the model was nvmax = 6.

您可以在本插入符号中查看有关使用跳跃选择变量的更多信息。插入符号确实训练不同的模型,但通常使用不同的超参数来完成。你可以查看一个。超参数无法直接从数据中学习,因此需要进行培训。这些参数决定了模型的行为方式,例如lasso中的lambda决定了对模型应用了多少正则化

在glm中,没有要训练的超参数。我想你要找的是从许多潜在变量中选择最好的线性模型。您可以使用步骤()

另一种选择是使用带插入符号的跳跃,例如,上述等效项为:

train(mpg~ .,data=mtcars,method='leapBackward', trControl=trainControl(method="cv",number=10),tuneGrid=data.frame(nvmax=2:6)) 

Linear Regression with Backwards Selection 

32 samples
10 predictors

No pre-processing
Resampling: Cross-Validated (10 fold) 
Summary of sample sizes: 30, 28, 28, 28, 30, 28, ... 
Resampling results across tuning parameters:

  nvmax  RMSE      Rsquared   MAE     
  2      3.299712  0.9169529  2.783068
  3      3.124146  0.8895539  2.750305
  4      3.249803  0.8849213  2.853777
  5      3.258143  0.8939493  2.823721
  6      3.123481  0.8917197  2.723475

RMSE was used to select the optimal model using the smallest value.
The final value used for the model was nvmax = 6.
在本文中,您可以查看有关使用跳跃选择变量的更多信息