Skip to contents

J = MSE + 2 r alpha L1 + (1-r)(alpha/m) L2.

Usage

morie_geron_ch4_elastic_net_cost_function(
  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_ch4_elastic_net_cost_function(X, y, th, 0.4, 0.6)
#> $cost
#> [1] 1.0189
#> 
#> $mse
#> [1] 0.4425
#> 
#> $l1_penalty
#> [1] 0.528
#> 
#> $l2_penalty
#> [1] 0.0484
#> 
#> $l1_norm
#> [1] 1.1
#> 
#> $l2_norm_sq
#> [1] 1.21
#> 
#> $alpha
#> [1] 0.4
#> 
#> $r
#> [1] 0.6
#> 
#> $estimate
#> [1] 1.0189
#> 
#> $n
#> [1] 4
#>