I am fitting a logistic regression model to a training data set in R, more specifically a LASSO regression with an L1 penalty. I used the glmnet
package for that. The code for the model looks like this.
t1 <- Sys.time()
glmnet_classifier <- cv.glmnet(x = dtm_train_tfidf,
y = tweets_train[['sentiment']],
family = 'binomial',
# L1 penalty
alpha = 1,
# interested in the area under ROC curve
type.measure = "auc",
# 5-fold cross-validation
nfolds = 5,
# high value is less accurate, but has faster training
thresh = 1e-3,
# again lower number of iterations for faster training
maxit = 1e3)
print(difftime(Sys.time(), t1, units = 'mins'))
preds <- predict(glmnet_classifier, dtm_test_tfidf, type = 'response')[ ,1]
Now I would like to plot the ROC-curve. However, I cannot figure out how to accurately plot it.
When I plot(glmnet_classifier)
this is what I receive:
Since this is not the Roc-curve, I would like to know if anybody knows how to plot it in R? I already referred to the ROCR
package, but it gives me an error:
roc.perf = performance(preds, measure = "tpr", x.measure = "fpr")
Can anybody help? Thank you very much!