Train an Elastic Net (L1 and L2 Regularized Logistic Regression) Model for Classification
Source:R/diagnosis.R
en_dia.Rd
Trains an Elastic Net-regularized logistic regression model
using caret::train
(via glmnet
method) for binary classification.
Value
A caret::train
object representing the trained Elastic Net model.
Examples
# \donttest{
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)
#> glmnet
#>
#> 50 samples
#> 2 predictor
#> 2 classes: 'Control', 'Case'
#>
#> No pre-processing
#> Resampling: Cross-Validated (5 fold)
#> Summary of sample sizes: 40, 40, 40, 40, 40
#> Resampling results:
#>
#> ROC Sens Spec
#> 0.475 0.1 0.9
#>
#> Tuning parameter 'alpha' was held constant at a value of 0.5
#> Tuning
#> parameter 'lambda' was held constant at a value of 0.01
# }