1

我不明白为什么数据集的测试在 R 神经网络(nnet包)中不起作用。

我有两个具有相似结构的数据集 - 用于训练(trainset17 个案例)和预测(testset9 个案例)。每个数据集都有列:AgeGenderHeightWeight。在测试数据集中,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))
    
4

1 回答 1

0

我认为在 R 神经网络包中,用于预测的命令是“计算”,而不是预测,这非常令人困惑。一个

于 2016-03-24T11:11:51.850 回答