0

I would like to make sure that I am using the prediction method here correctly; maybe I am misinterpreting the parameter "s" here!? My intent is to use the best lambda obtained from cross validation to make my final predictions on a holdout dataset.

# set alpha to 1 for lasso
cv.fit <- cv.glmnet(x = mat, y = class, family = "binomial", alpha = 1, nfolds = 10)

val.m <- as.matrix(val.df[, -match(c("Id", "class"), names(val.df))])
preds <- predict(cv.fit, val.m, type="response", s = cv.lasso.fit$lambda.min)

It would be nice if someone could give me reassurance.

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
CodingButStillAlive
  • 733
  • 2
  • 8
  • 22
  • 1
    You're using it right, the `s =` specifies the lambda value. – David Robinson May 05 '17 at 17:49
  • Thank you. I wondered, because the average cross validation error rate does not match my results on the validation set at all. On the validation set, the model always predicts the -1 class. Its strange, but good to know that it is not due to an error in these commands. – CodingButStillAlive May 05 '17 at 17:58

0 Answers0