Description Usage Arguments Value Author(s) Examples
Prediction of artificial neural network of class nn
, produced by neuralnet()
.
1 2 |
object |
Neural network of class |
newdata |
New data of class |
rep |
Integer indicating the neural network's repetition which should be used. |
all.units |
Return output for all units instead of final output only. |
... |
further arguments passed to or from other methods. |
Matrix of predictions. Each column represents one output unit.
If all.units=TRUE
, a list of matrices with output for each unit.
Marvin N. Wright
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(neuralnet)
# Split data
train_idx <- sample(nrow(iris), 2/3 * nrow(iris))
iris_train <- iris[train_idx, ]
iris_test <- iris[-train_idx, ]
# Binary classification
nn <- neuralnet(Species == "setosa" ~ Petal.Length + Petal.Width, iris_train, linear.output = FALSE)
pred <- predict(nn, iris_test)
table(iris_test$Species == "setosa", pred[, 1] > 0.5)
# Multiclass classification
nn <- neuralnet((Species == "setosa") + (Species == "versicolor") + (Species == "virginica")
~ Petal.Length + Petal.Width, iris_train, linear.output = FALSE)
pred <- predict(nn, iris_test)
table(iris_test$Species, apply(pred, 1, which.max))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.