Я сделал MLP с двумя входами и одним выходом, используя пакет R Keras . Моя выходная переменная должна иметь положительные значения, поэтому я использовал функцию активации Relu для выходного слоя. Я не мог обучить сеть, даже после того, как попробовал разные значения для нейронов скрытого слоя. Подходит ли функция активации relu для моей работы? Или я должен использовать любую другую структуру сети? Мой набор данных содержит 441 выборочную точку и доступен здесь .
Мои коды следующие:
Keras_ANN<-function(x_tr,y_tr, N_input=2){
require(keras)
# x_tr <- scale(x_tr)
model <- keras_model_sequential()
model %>%
layer_dense(units = 10, activation = 'tanh', input_shape = N_input) %>%
layer_dropout(rate = 0.2) %>%
# layer_dense(units = 5) %>%
layer_dense(units = 1, activation = "relu")
model %>% compile(
loss = "mse",
optimizer = optimizer_rmsprop(),
metrics = list("mean_absolute_error")
)
# Display training progress by printing a single dot for each completed epoch.
print_dot_callback <- callback_lambda(
on_epoch_end = function(epoch, logs) {
if (epoch %% 80 == 0) cat("\n")
cat(".")
}
)
#
epochs <- 500
# # Fit the model and store training stats
# The patience parameter is the amount of epochs to check for improvement.
early_stop <- callback_early_stopping(monitor = "val_loss", patience = 10)
history <- model %>% fit(
x_tr,
y_tr,
epochs = epochs,
validation_split = 0.1,
verbose = 0,
callbacks = list(early_stop, print_dot_callback)
)
# plot(history, metrics = "mean_absolute_error", smooth = FALSE)
return(model)
}
input<-as.matrix(Mydata[,1:2])
target<-as.matrix(Mydata[,3])
model<-Keras_ANN(input, target, N_input = 2)
plot(target, model %>% predict(input))