Cross Validated Asked by fcas80 on November 12, 2021
Well, in R if you want to use the ROCR
package, you use it on your test data. I think it is crucial to understand the steps involved prior to the plotting of the ROC curve.
train data
and test data
.train data
.train data
, you can now use it predict the outcome of your dependent variable based on all the independent variables from your test data
.test data
.test data
.Below is a code for further elaboration, here glmnet
is used, where newx
is set to be the test data
:
training.samples <- df$dependent %>% createDataPartition(p = 0.8, list = FALSE)
train <- df[training.samples, ]
test <- df[-training.samples, ]
x.train <- data.frame(train[, names(train) != "dependent"])
y.train <- train$dependent
x.test <- data.frame(test[, names(test) != "dependent"])
y.test <- test$dependent
model <- glmnet(x.train, y.train, family = "whatever you need")
coef <- coef(model, s = lambda.1se)
predicted <- predict(model, s = lambda.1se, newx = x.test)
t <- 0.4
predict_binary <- ifelse(predicted > t, 1, 0)
CM <- confusionMatrix(as.factor(predict_binary), as.factor(y.test))
pred <- prediction(predict_binary, y.test)
perf <- performance(pred, "tpr", "fpr")
plot(perf)
auc_ROCR <- performance(pred, measure = "whatever you need")
auc_ROCR <- [email protected][[1]]
auc_ROCR
Answered by Thomas on November 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP