我不明白为什么数据集的测试在 R 神经网络(nnet
包)中不起作用。
我有两个具有相似结构的数据集 - 用于训练(trainset
17 个案例)和预测(testset
9 个案例)。每个数据集都有列:Age
、Gender
、Height
、Weight
。在测试数据集中,age
未知 ( NaN
)。
训练公式如下:
library(nnet)
trainednetwork<-nnet(age~gender+emLength+action5cnt,trainset, size=17)
无论如何,如果我尝试在代码的下一个字符串中使用测试数据集进行预测,
prediction<-predict(trainednetwork,testset)
我弄错了"No component terms, no attribute"
。任何人都可以帮忙吗?
数据(通过dput()
函数获得):
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))