If i do a modelLookup('glmnet') it says TRUE for probModel (and in fact, I'd expect it to be usable as a model to predict probabilities in a binary outcome prediction problem as glmnet has a 'binomial' family argument).

However, following the instructions from the caret package I say:

trainControl = trainControl(classProbs=TRUE)

modelFit = train(X, y, method='glmnet', trControl=trainControl)

and I get:

cannot compute class probabilities for regression

Am I doing something wrong?


1 Answer 1


I suspect your y is of class numeric and is not an R factor. You can look at the documentation for glmnet directly,

   y: response variable. Quantitative for ‘family="gaussian"’ or
      ‘family="poisson"’ (non-negative counts). For
      ‘family="binomial"’ should be either a **factor with two
      levels, or a two-column matrix of counts or proportions**.

(emphasize is mine.)

or check it with the following toy example:

iris.sub <- subset(iris, Species %in% c("setosa", "versicolor"))
train(iris.sub[,1:4], factor(iris.sub$Species), method='glmnet', 
      trControl=trainControl(classProbs=TRUE))  # work
train(iris.sub[,1:4], as.numeric(iris.sub$Species), method='glmnet', 
      trControl=trainControl(classProbs=TRUE))  # 'cannnot compute class probabilities for regression'
  • $\begingroup$ Spot on! I was pretty sure my y was of factor type but i had the factor(y.train) part commented out so it was integer type. Thanks!! $\endgroup$ Apr 8, 2012 at 22:01

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.