This question might be better suited to stackoverflow, though you have not given a reproducible example.
The following predicts the species class label for the iris dataset, adapting the example from ?train
library(caret)
library(MASS)
data(iris)
set.seed(1)
TestRows <- c(sample(50,15), sample(50,15)+50, sample(50,15)+100)
TrainData <- iris[-TestRows,1:4]
TrainClasses <- iris[-TestRows,5]
TestData <- iris[TestRows,1:4]
TestClasses <- iris[TestRows,5]
nnetFit <- train(x=TrainData, y=TrainClasses,
method = "nnet",
preProcess = "range",
tuneLength = 2,
trace = FALSE,
maxit = 100)
and gives the following result for the training set:
> table(TrainClasses, predict(nnetFit))
TrainClasses setosa versicolor virginica
setosa 35 0 0
versicolor 0 34 1
virginica 0 1 34
and for the test set
> table(TestClasses, predict(nnetFit,TestData))
TestClasses setosa versicolor virginica
setosa 15 0 0
versicolor 0 15 0
virginica 0 3 12
which I find surprisingly accurate for the versicolor/virginica distinction