Skip to content

Instantly share code, notes, and snippets.

@lundquist-ecology-lab
Last active January 16, 2023 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lundquist-ecology-lab/63c464b00ef60a7041928cb5cb7de8ec to your computer and use it in GitHub Desktop.
Save lundquist-ecology-lab/63c464b00ef60a7041928cb5cb7de8ec to your computer and use it in GitHub Desktop.
Artificial neural network (ANN) analysis in R using iris data
# Load data
data <- iris
# Split data into training and testing sets
set.seed(123)
index <- sample(1:nrow(data), 0.8 * nrow(data))
train <- data[index,]
test <- data[-index,]
# Build ANN model
library(caret)
model <- train(Species ~ ., data = train, method = "mlp", trControl = trainControl(method = "cv", number = 5))
# Make predictions on the test set
predictions <- predict(model, newdata = test)
# Evaluate the model's performance
confusionMatrix(predictions, test$Species)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment