vignettes/elastic-net.R

## ---- echo = FALSE, message = FALSE-------------------------------------------
library(beset)
suppressPackageStartupMessages(library(tidyverse))

## -----------------------------------------------------------------------------
set.seed(42)
data <- cbind(swiss, matrix(replicate(5, rnorm(nrow(swiss))), ncol = 5))
names(data)[7:11] <- paste0("noise", names(data)[7:11])

## -----------------------------------------------------------------------------
mod <- beset_elnet(Fertility ~ ., data)

## ---- fig.height=4, fig.width=5-----------------------------------------------
plot(mod)

## -----------------------------------------------------------------------------
mod_sum <- summary(mod, oneSE = FALSE)
mod_sum

## -----------------------------------------------------------------------------
summary(mod)

## -----------------------------------------------------------------------------
summary(mod, alpha = 0.01)

## -----------------------------------------------------------------------------
mod <- beset_elnet(Fertility ~ ., data, nest_cv = TRUE)

## ---- fig.height=4, fig.width=5-----------------------------------------------
plot(mod)

## -----------------------------------------------------------------------------
mod_sum <- summary(mod)
mod_sum

## -----------------------------------------------------------------------------
summary(mod, robust = TRUE)

## -----------------------------------------------------------------------------
summary(mod, oneSE = FALSE)

## -----------------------------------------------------------------------------
summary(mod, robust = TRUE) %>% print(metric = "mse")

## -----------------------------------------------------------------------------
validate(mod, metric = "auto", oneSE = TRUE, alpha = NULL, lambda = NULL)

## -----------------------------------------------------------------------------
summary(prostate)

## -----------------------------------------------------------------------------
mod <- beset_elnet(tumor ~ ., data = prostate, family = "binomial",
                   nest_cv = TRUE)
summary(mod)

## ---- fig.height=4, fig.width=5-----------------------------------------------
plot(mod)

## ---- fig.height=4, fig.width=5-----------------------------------------------
plot(mod) + ylab("Log-loss")

## ---- fig.height=4, fig.width=5-----------------------------------------------
plot(mod, metric = "auc")

## -----------------------------------------------------------------------------
summary(mod, metric = "auc") %>% print(metric = "auc")
jashu/beset documentation built on April 20, 2023, 5:28 a.m.