r - 模型选择是否使用交叉验证?
问题描述
所以这开始让我有点困惑。例如,具有以下训练 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"
)
我预计这会训练几个模型,然后选择在灵敏度上表现最好的模型。然而,当我阅读交叉验证时,我发现最多的是它如何用于计算平均性能分数。
我的假设错了吗?
解决方案
caret 确实训练了不同的模型,但通常使用不同的超参数来完成。您可以查看该过程的说明。超参数不能直接从数据中学习,所以你需要训练过程。这些参数决定了你的模型将如何表现,例如你在套索中有 lambda,它决定了对模型应用了多少正则化。
在 glm 中,没有要训练的超参数。我想您正在寻找的是从许多潜在变量中选择最佳线性模型的东西。您可以使用 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.
您可以在本网站上查看有关使用跳跃的变量选择的更多信息
推荐阅读
- python - 根据两个特征计算特征 Pandas 生成两个新列
- java - runtime_flags 中设置的未知位:0x8000
- windows-installer - InstallShield 如何将程序添加到“最近添加”列表中
- c++ - 为什么非空初始化静态成员 std::string 为空(在共享库中)?
- angular - 在子模块中访问路由 ID
- python - While 循环正确轮询 json 响应 api
- angular - Elementor wordpress + React 或 Angular
- maven - 如何在 jenkins 中重新运行 cucumber-jvm 失败的测试用例
- devops - GIT中用于将现有更改文件提升到远程分支的命令序列应该是什么
- javascript - 如何将自定义 HTML 添加到 ngx Typeahead?