library(keras)
build_model <- function() {
model <- keras_model_sequential() %>%
layer_dense(units = 64, activation = "relu",
input_shape = dim(train_data)[[2]]) %>%
regularizer_l1_l2(l1 = 0.01, l2 = 0.01) %>%
layer_dense(units = 64, activation = "relu") %>%
regularizer_l1_l2(l1 = 0.01, l2 = 0.01) %>%
layer_dense(units = 1)
model %>% compile(
optimizer = "rmsprop",
loss = "mse",
metrics = c("mae")
)
}
model <- build_model()
我尝试使用R中的keras应用L1和L2正则化。然而,我得到一个错误:
Error in regularizer_l1_l2(., l1 = 0.01, l2 = 0.01) : unused argument (.)
我使用的正则化语法与链接中提到的语法相同。https://keras.rstudio.com/reference/regularizer_l1.html有人能告诉我我做错了什么吗?
1条答案
按热度按时间7bsow1i61#
这将是使用R中的keras进行L1和L2正则化的正确语法:
可重复实施例: