NomNonYon
NomNonYon

Reputation: 87

Caret Logistic model results in NULL model

I am not sure what is happening here. When I create the model outside of caret it seems to work ok. However when using caret to get a cv I get NULL when I get a summary of the model. I also get an error when I try to plot the model. The response variable is a factor

data_ctrl = trainControl(method = "cv", number = 10)

model_caret1 = train(Clicked.on.Ad~ Age+ Area.Income+Daily.Internet.Usage + Daily.Time.Spent.on.Site,
                     data = Ads,
                     trControl = data_ctrl,
                     method = "glm",
                     family=binomial())

It results in the following:

all:
NULL

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.4578  -0.1341  -0.0333   0.0167   3.1961  

Coefficients:
                            Estimate  Std. Error z value             Pr(>|z|)    
(Intercept)              27.12906491  2.71436398   9.995 < 0.0000000000000002 ***
Age                       0.17092126  0.02568321   6.655    0.000000000028334 ***
Area.Income              -0.00013539  0.00001868  -7.247    0.000000000000425 ***
Daily.Internet.Usage     -0.06391289  0.00674508  -9.475 < 0.0000000000000002 ***
Daily.Time.Spent.on.Site -0.19192952  0.02065752  -9.291 < 0.0000000000000002 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 1386.3  on 999  degrees of freedom
Residual deviance:  182.9  on 995  degrees of freedom
AIC: 192.9

Number of Fisher Scoring iterations: 8
> plot(model_caret1)
Error in plot.train(model_caret1) : 
  There are no tuning parameters for this model.

Upvotes: 1

Views: 378

Answers (1)

StupidWolf
StupidWolf

Reputation: 46908

The object you obtained is a train object and i am guessing what you need to do is a plot on the glm object. So you need to look for the final fitted model:

library(caret)
dat = iris
dat$Species = factor(ifelse(dat$Species=="versicolor","v","o"))

data_ctrl = trainControl(method = "cv", number = 10)

model_caret1 = train(Species ~ .,
                     data = dat,
                     trControl = data_ctrl,
                     method = "glm",
                     family=binomial())

class(model_caret1)
[1] "train"         "train.formula"

Then under this:

class(model_caret1$finalModel)
[1] "glm" "lm" 

summary(model_caret1$finalModel)

plot(model_caret1$finalModel)

Upvotes: 1

Related Questions