2017-12-14 48 views
3

caret package을 사용하는 로지스틱 회귀 모델을 R로 맞추려고합니다.R 캐럿 패키지의 로지스틱 회귀 튜닝 매개 변수 격자?

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))) 

는 그러나, 나는 튜닝 파라미터는이 모델이 될해야하는지 확실하지 오전과 내가 찾는 힘든 시간을 보내고 있어요 : 나는 다음과 같은 했어요. C가 sklearn에 사용 된 매개 변수이기 때문에 나는 C라고 가정했습니다. 현재 다음 오류가 발생합니다. -

Error: The tuning parameter grid should have columns parameter

해결 방법에 대한 의견이 있으십니까?

+0

시도'modelLookup ("GLM") ', 여기를 참조하십시오 : https://stackoverflow.com/questions/43970831/the-tuning-parameter-in-glm-vs-rf/44010331#44010331 –

+0

그것을 'tuneLength'를 지정하고 그리드의 스펙이 급격히 변하는 대신에 변화하기로 결정된 '캐럿 (catcht)'매개 변수를 관찰하는 것부터 시작하는 것이 좋습니다. – dmi3kno

+0

'glm' 메소드에는 튜닝 매개 변수가 없습니다. https://topepo.github.io/caret/train-models-by-tag.html, 거기에는 더미 튜닝 매개 변수가 있습니다. 아무 것도하지 않습니다. – jmuhlenkamp

답변

1

웹 사이트의 경우 - search for method = 'glm' herecaret 내에 조정 매개 변수가 없습니다.

enter image description here

우리는 쉽게이 몇 가지 기본적인 train 호출을 테스트하여 경우가 확인할 수 있습니다. 우선 웹 서적 당 튜닝 파라미터 (cp)를 가지고있는 메소드 (rpart)부터 시작해 보겠습니다.

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. 

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 

위의 경우 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.