en_dia: Train an Elastic Net (L1 and L2 Regularized Logistic...

View source: R/diagnosis.R

en_diaR Documentation

Train an Elastic Net (L1 and L2 Regularized Logistic Regression) Model for Classification

Description

Trains an Elastic Net-regularized logistic regression model using caret::train (via glmnet method) for binary classification.

Usage

en_dia(X, y, tune = FALSE, cv_folds = 5)

Arguments

X

A data frame of features.

y

A factor vector of class labels.

tune

Logical, whether to perform hyperparameter tuning for lambda (if TRUE) or use a fixed value (if FALSE). alpha is fixed at 0.5 for Elastic Net.

cv_folds

An integer, the number of cross-validation folds for caret.

Value

A caret::train object representing the trained Elastic Net model.

Examples


set.seed(42)
n_obs <- 50
X_toy <- data.frame(
  FeatureA = rnorm(n_obs),
  FeatureB = runif(n_obs, 0, 100)
)
y_toy <- factor(sample(c("Control", "Case"), n_obs, replace = TRUE),
                levels = c("Control", "Case"))

# Train the model
en_model <- en_dia(X_toy, y_toy)
print(en_model)


E2E documentation built on Aug. 27, 2025, 1:09 a.m.