我无法理解为什么数据集的测试不适用于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))
答案 0 :(得分:0)
我认为在R神经网络包中,用于预测的命令是&#34;计算&#34;而不是预测,这是非常令人困惑的。甲