0
$\begingroup$

I have a quick question I can't seem to find a good answer to, so I hope this makes sense and please let me know of any important information I may leave out.

I've been using the machine learning functions of caret recently and have the below syntax:

controlroc <- trainControl(method = "repeatedcv", 
                           number = 10,
                           repeats = 5,
                           savePredictions = "final",
                           classProbs = TRUE,
                           selectionFunction = "oneSE", 
                           summaryFunction = twoClassSummary, allowParallel = TRUE )

set.seed(1234)

model_listworks <- caretList(
  DV ~., 
  data = train,
  trControl=controlroc,
  metric="ROC",
  tuneList=list( 
    glmmodel = caretModelSpec(method="glm", family = "binomial"),
    enetmodel=caretModelSpec(method="glmnet", tuneGrid = expand.grid (alpha = c (0, .1, .2, .4, .6, .8, 1), lambda = seq (.01, .2, length = 40))),
    rfmodel = caretModelSpec(method="rf", tuneGrid = expand.grid (.mtry=c(1:10)), ntrees = 1000)
  ) 
)

This has worked really well but now I'm trying to pull some basic GLM coefficients produced in the model_listworks. The syntax used to grab my GLM coefficients is relatively simple:

coef(model_listworks$glmmodel$finalModel)

The problem I seem to be having is that I can't identify if these coefficients are standardized (they appear to be based on visual inspection) and further, if they are standardized via the IV or DV. I do find this funny as the rest of this process was generally seamless, but now I can't seem to find the appropriate sources.

$\endgroup$

1 Answer 1

1
$\begingroup$

They are not standardized since you did not specify preProcess=.. when training the model. Using an example dataset:

library(caret)
library(caretEnsemble)
set.seed(1234)

train = iris
train$DV = factor(ifelse(train$Species == "versicolor","v","o"))
train$Species=NULL

model_listworks <- caretList(
  DV ~., 
  data = train,
  trControl=controlroc,
  metric="ROC",
  tuneList=list( 
    glmmodel = caretModelSpec(method="glm", family = "binomial"),
    enetmodel=caretModelSpec(method="glmnet", tuneGrid = expand.grid (alpha = c (0, .1, .2, .4, .6, .8, 1), lambda = seq (.01, .2, length = 40))),
    rfmodel = caretModelSpec(method="rf", tuneGrid = expand.grid (.mtry=c(1:3)), ntrees = 100)
  ) 
)

 coef(model_listworks$glmmodel$finalModel)
 (Intercept) Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
   7.3784866   -0.2453567   -2.7965681    1.3136433   -2.7783439 

Check this against if you would just fit a linear model:

coef(glm(DV ~ .,data=train,family="binomial"))
 (Intercept) Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
   7.3784866   -0.2453567   -2.7965681    1.3136433   -2.7783439 
$\endgroup$
2
  • $\begingroup$ Thank you so much! I have one follow-up question then. Once I add preProcess option, this would standardize the features/IV, correct? $\endgroup$
    – JCPsy
    Commented Jul 7, 2020 at 14:50
  • $\begingroup$ Yes that's correct $\endgroup$
    – StupidWolf
    Commented Jul 7, 2020 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.