Last active
January 16, 2023 22:04
-
-
Save lundquist-ecology-lab/63c464b00ef60a7041928cb5cb7de8ec to your computer and use it in GitHub Desktop.
Artificial neural network (ANN) analysis in R using iris data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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