# NOT RUN {
# Example on iris dataset
# Prepare test and train sets
random_draw <- sample(1:nrow(iris), size = 100)
X_train <- iris[random_draw, 1:4]
y_train <- iris[random_draw, 5]
X_test <- iris[setdiff(1:nrow(iris), random_draw), 1:4]
y_test <- iris[setdiff(1:nrow(iris), random_draw), 5]
# Train neural network on classification task
NN <- neuralnetwork(X = X_train, y = y_train, hidden.layers = c(5, 5),
optim.type = 'adam', learn.rates = 0.01, val.prop = 0)
# Plot the loss during training
plot(NN)
# Make predictions
y_pred <- predict(NN, newdata = X_test)
# Plot predictions
correct <- (y_test == y_pred$predictions)
plot(X_test, pch = as.numeric(y_test), col = correct + 2)
# }
Run the code above in your browser using DataLab