所以这开始让我感到困惑。例如,具有以下代码来训练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"
)
我希望这会训练一些模型,然后选择在灵敏度上表现最佳的模型。但是,当我阅读交叉验证时,最能发现的是如何使用它来计算平均性能得分。
我的假设错了吗?
答案 0 :(得分:0)
插入符号可以训练不同的模型,但是通常使用不同的超参数来完成。您可以签出an explanation of the process。无法从数据中直接学习超级参数,因此您需要训练过程。这些参数决定了模型的行为方式,例如,套索中有lambda来决定对模型应用多少正则化。
一目了然,没有要训练的超参数。我猜您正在寻找的是从许多潜在变量中选择最佳线性模型的方法。您可以使用step()
fit = lm(mpg ~ .,data=mtcars)
step(fit,direction="back")
另一种选择是将插入符号与跳转一起使用,例如,与上面相同的是:
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.
您可以在此website
中使用跃点查看更多有关变量选择的信息。