I can't get why the testing of dataset is not working in R neural networks (nnet
package).
I have two datasets with similar structures - for training (trainset
, 17 cases) and prediction (testset
, 9 cases). Each dataset has columns: Age
, Gender
, Height
, Weight
. In the testing dataset the age
is unknown (NaN
).
The formula for training is obtained successfully below:
library(nnet)
trainednetwork<-nnet(age~gender+emLength+action5cnt,trainset, size=17)
Anyway, if I try to use test dataset for prediction in the next string of the code,
prediction<-predict(trainednetwork,testset)
I get mistake "No component terms, no attribute"
. Can anyone help?
The data (obtained with dput()
function):
testset
:structure(list( age = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_), gender = structure( c(2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 2L), .Label = c("f", "m"), class = "factor"), Height= c(9L, 11L, 9L, 11L, 9L, 11L, 9L, 11L, 9L), Weight= c(1L, 41L, 2L, 1L, 2L, 29L, 12L, 6L, 12L)), .Names = c("age", "gender", "Height", "Weight"), class = "data.frame", row.names = c(NA, 9L))
trainset
:structure(list( age = c(43L, 35L, 22L, 28L, 20L, 47L, 41L, 23L, 42L, 27L, 22L, 60L, 62L, 47L, 42L, 26L, 54L), gender = structure( c(2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("f", "m"), class = "factor"), Height= c(7L, 9L, 11L, 11L, 11L, 9L, 11L, 9L, 23L, 9L, 9L, 9L, 10L, 7L, 7L, 11L, 7L), Weight= c(2L, 2L, 9L, 9L, 28L, 8L, 6L, 3L, 1L, 2L, 40L, 1L, 9L, 1L, 7L, 4L, 35L)), .Names = c("age", "gender", "Height", "Weight"), class = "data.frame", row.names = c(NA, 17L))