gpt4 book ai didi

R 插入符 : Tuning GLM boost prune parameter

转载 作者:行者123 更新时间:2023-12-01 19:21:30 25 4
gpt4 key购买 nike

我正在尝试调整 GLM boost 模型的参数。根据Caret package documentation对于这个模型,有 2 个参数可以调整,mstop 和 prune。

    library(caret)
library(mlbench)

data(Sonar)

set.seed(25)
trainIndex = createDataPartition(Sonar$Class, p = 0.9, list = FALSE)
training = Sonar[ trainIndex,]
testing = Sonar[-trainIndex,]

### set training parameters
fitControl = trainControl(method = "repeatedcv",
number = 10,
repeats = 10,
## Estimate class probabilities
classProbs = TRUE,
## Evaluate a two-class performances
## (ROC, sensitivity, specificity) using the following function
summaryFunction = twoClassSummary)

### train the models
set.seed(69)
# Use the expand.grid to specify the search space
glmBoostGrid = expand.grid(mstop = c(50, 100, 150, 200, 250, 300),
prune = c('yes', 'no'))

glmBoostFit = train(Class ~ .,
data = training,
method = "glmboost",
trControl = fitControl,
tuneGrid = glmBoostGrid,
metric = 'ROC')
glmBoostFit

输出如下:

Boosted Generalized Linear Model 

188 samples
60 predictors
2 classes: 'M', 'R'

No pre-processing
Resampling: Cross-Validated (10 fold, repeated 10 times)
Summary of sample sizes: 169, 169, 169, 169, 170, 169, ...
Resampling results across tuning parameters:

mstop ROC Sens Spec ROC SD Sens SD Spec SD
50 0.8261806 0.764 0.7598611 0.10208114 0.1311104 0.1539477
100 0.8265972 0.729 0.7625000 0.09459835 0.1391250 0.1385465
150 0.8282083 0.717 0.7726389 0.09570417 0.1418152 0.1382405
200 0.8307917 0.714 0.7769444 0.09484042 0.1439011 0.1452857
250 0.8306667 0.719 0.7756944 0.09452604 0.1436740 0.1535578
300 0.8278403 0.728 0.7722222 0.09794868 0.1425398 0.1576030

Tuning parameter 'prune' was held constant at a value of yes
ROC was used to select the optimal model using the largest value.
The final values used for the model were mstop = 200 and prune = yes.

修剪参数保持不变(调整参数“修剪”的值保持恒定为 yes),尽管 glmBoostGrid 还包含 prune == no 。我查看了mboost包文档中的boost_control方法,只有mstop参数可以访问,那么如何修剪prune 参数可以使用 train 方法的 tuneGrid 参数进行调整吗?

最佳答案

差异在于 glmboost 调用的这一部分:

if (param$prune == "yes") {
out <- if (is.factor(y))
out[mstop(AIC(out, "classical"))]
else out[mstop(AIC(out))]
}

区别在于 aic 的计算方式。但是,在插入符号中使用 glmboost 运行各种测试时,我怀疑它的行为是否符合预期。我在 github 上创建了一个问题来看看我的怀疑是否正确。如果开发人员提供更多信息,我将编辑我的答案。

关于R 插入符 : Tuning GLM boost prune parameter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36222008/

25 4 0