Predicting labels based on a model trained by nnet
As we have trained a neural network with nnet
in the previous recipe, we can now predict the labels of the testing dataset based on the trained neural network. Furthermore, we can assess the model with a confusion matrix adapted from the caret
package.
Getting ready
To complete this recipe, you need to have completed the previous recipe by generating the training dataset, trainset
, and the testing dataset, testset
, from the iris
dataset. The trained neural network also needs to be saved as iris.nn
.
How to do it...
Perform the following steps to predict labels based on the trained neural network:
- Generate the predictions of the testing dataset based on the model,
iris.nn
:
> iris.predict = predict(iris.nn, testset, type="class")
- Generate a classification table based on the predicted labels and labels of the testing dataset:
> nn.table = table(testset$Species, iris.predict) iris.predict setosa versicolor virginica setosa 17 0 0...