R Caret软件包中的Logistic回归调整参数网格?

Jan*_*lly 5 r logistic-regression hyperparameters r-caret

我正在尝试使用来拟合R中的逻辑回归模型caret package。我已经完成以下工作:

model <- train(dec_var ~., data=vars, method="glm", family="binomial",
                 trControl = ctrl, tuneGrid=expand.grid(C=c(0.001, 0.01, 0.1, 1,10,100, 1000)))
Run Code Online (Sandbox Code Playgroud)

但是,我不确定该模型的调整参数应该是什么,并且我很难找到它。我假设它是C,因为C是中使用的参数sklearn。目前,我收到以下错误-

错误:调整参数网格应具有列参数

您对如何解决此问题有任何建议吗?

jmu*_*amp 5

按最大值库恩的网络书- 搜索method = 'glm'这里,没有调整参数glmcaret

在此处输入图片说明

通过测试一些基本train调用,我们可以轻松地验证这种情况。首先,让我们从方法(rpart)开始,该方法的确对cp每个网络书都有调整参数()。

library(caret)
data(GermanCredit)

# Check tuning parameter via `modelLookup` (matches up with the web book)
modelLookup('rpart')
#  model parameter                label forReg forClass probModel
#1 rpart        cp Complexity Parameter   TRUE     TRUE      TRUE

# Observe that the `cp` parameter is tuned
set.seed(1)
model_rpart <- train(Class ~., data=GermanCredit, method='rpart')
model_rpart
#CART 

#1000 samples
#  61 predictor
#   2 classes: 'Bad', 'Good' 

#No pre-processing
#Resampling: Bootstrapped (25 reps) 
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ... 
#Resampling results across tuning parameters:

#  cp          Accuracy   Kappa    
#  0.01555556  0.7091276  0.2398993
#  0.03000000  0.7025574  0.1950021
#  0.04444444  0.6991700  0.1316720

#Accuracy was used to select the optimal model using  the largest value.
#The final value used for the model was cp = 0.01555556.
Run Code Online (Sandbox Code Playgroud)

我们看到cp参数已调整。现在开始尝试glm

# Check tuning parameter via `modelLookup` (shows a parameter called 'parameter')
modelLookup('glm')
#  model parameter     label forReg forClass probModel
#1   glm parameter parameter   TRUE     TRUE      TRUE

# Try out the train function to see if 'parameter' gets tuned
set.seed(1)
model_glm <- train(Class ~., data=GermanCredit, method='glm')
model_glm
#Generalized Linear Model 

#1000 samples
#  61 predictor
#   2 classes: 'Bad', 'Good' 

#No pre-processing
#Resampling: Bootstrapped (25 reps) 
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ... 
#Resampling results:

#  Accuracy   Kappa    
#  0.7386384  0.3478527
Run Code Online (Sandbox Code Playgroud)

在上述情况下,glm不会执行任何参数调整。从我的经验,它出现在parameter一个名为parameter只是一个占位符,而不是一个真正的调整参数。如以下代码所示,即使我们试图强迫它对其进行调整parameter,基本上也只执行一个值。

set.seed(1)
model_glm2 <- train(Class ~., data=GermanCredit, method='glm',
                    tuneGrid=expand.grid(parameter=c(0.001, 0.01, 0.1, 1,10,100, 1000)))
model_glm2
#Generalized Linear Model 

#1000 samples
#  61 predictor
#   2 classes: 'Bad', 'Good' 

#No pre-processing
#Resampling: Bootstrapped (25 reps) 
#Summary of sample sizes: 1000, 1000, 1000, 1000, 1000, 1000, ... 
#Resampling results across tuning parameters:

#  Accuracy   Kappa      parameter
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    
#  0.7386384  0.3478527  0.001    

#Accuracy was used to select the optimal model using  the largest value.
#The final value used for the model was parameter = 0.001.
Run Code Online (Sandbox Code Playgroud)