View source: R/BinomialModel.R
| BinomialAUC | R Documentation |
Computes Area Under the ROC Curve (AUC) for model predictions using the ROCR package. Handles binary classification models from glmnet.
BinomialAUC(model, newx, s, acture.y)
model |
Fitted glmnet model object. |
newx |
New data matrix for prediction. |
s |
Lambda value for prediction (e.g., "lambda.min" or numeric). |
acture.y |
Actual binary outcomes (numeric 0/1 or factor). |
Numeric AUC value between 0 and 1.
if (requireNamespace("glmnet", quietly = TRUE) &&
requireNamespace("ROCR", quietly = TRUE)) {
set.seed(123)
train_data <- matrix(rnorm(100 * 5), ncol = 5)
train_outcome <- rbinom(100, 1, 0.5)
test_data <- matrix(rnorm(50 * 5), ncol = 5)
test_outcome <- rbinom(50, 1, 0.5)
fitted_model <- glmnet::cv.glmnet(train_data, train_outcome, family = "binomial", nfolds = 5)
auc_value <- BinomialAUC(fitted_model, test_data, fitted_model$lambda.min, test_outcome)
print(auc_value)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.