Skip to contents

J = MSE + r alpha L1 + ((1-r)/2) alpha L2, stacked on morie_geron_lasso_cost() at r * alpha.

Usage

morie_geron_elastic_net_cost(X, y, theta, alpha, r, penalize_intercept = FALSE)

Arguments

X, y, theta

Design, targets and parameters.

alpha

Non-negative penalty weight.

r

L1 mix ratio in [0, 1].

penalize_intercept

Include theta[1] in both penalties.

Value

List with cost, mse, l1_penalty, l2_penalty, l1_norm, l2_norm_sq.

Examples

X <- matrix(c(1, 2, 1, 3, 1, 5, 1, 7), 4, byrow = TRUE)
y <- c(2, 3, 6, 9)
th <- c(0.5, 1.1)
morie_geron_elastic_net_cost(X, y, th, 0.4, 0.6)
#> $cost
#> [1] 0.8033
#> 
#> $mse
#> [1] 0.4425
#> 
#> $l1_penalty
#> [1] 0.264
#> 
#> $l2_penalty
#> [1] 0.0968
#> 
#> $l1_norm
#> [1] 1.1
#> 
#> $l2_norm_sq
#> [1] 1.21
#> 
#> $alpha
#> [1] 0.4
#> 
#> $r
#> [1] 0.6
#> 
#> $estimate
#> [1] 0.8033
#> 
#> $n
#> [1] 4
#>