Reputation: 199
I am trying to plot a ROC curve for my glmnet
regression model. In order to do that, I am trying to predict using type = "response" in predict function:
pred_glmnet_s10_2class <- predict(model_train_glmnet_s10_2class,
newdata=testing_s10_2class,
s = "model_train_glmnet_s10_2class$finalModel$lambdaOpt",
type="response")
and I get the following error:
Error in predict.train(model_train_glmnet_s10_2class, newdata = testing_s10_2class, : type must be either "raw" or "prob"
My predictions and class labels are binary 0 and 1 and have been factored. Any help is really appreciated. Also, any ideas on how to plot AUC (Area Under ROC curve) vs number of features? Thanks!
Upvotes: 0
Views: 6879
Reputation: 14331
Assuming that model_train_glmnet_s10_2class
was generated by train
(showing the code would be helpful)...
Using predict(model_train_glmnet_s10_2class)
is using predict.train
and uses the optimal lambda values determined by train
automatically. If you want the probabilities, just use type = "prob"
.
Your syntax is consistent with predict.glmnet
and not predict.train
.
As said in the documentation, it is a really bad idea to use model_train_glmnet_s10_2class$finalModel
directly to do the predictions
Upvotes: 2