繁体   English   中英

用神经网络在R中计算?

[英]compute with neural network in R?

allClassifiers中的所有元组是1或2,例如

    naiveBayesPrediction    knnPred5    knnPred10   dectreePrediction   logressionPrediction    correctClass
    1                       2                1           1                     1                          1
    1                       2                1           1                     1                          1
    1                       2                1           1                     1                          1
    1                       2                1           2                     1                          1

我训练了合奏者

ensembleModel <- neuralnet(correctClass ~ naiveBayesPrediction + knnPred5 + knnPred10 + dectreePrediction + logressionPrediction, data=allClassifiers[ensembleTrainSample,])

但是我试图用它来预测:

compute(ensembleModel, allClassifiers[ensembleTestSample,])$net.result

但是我得到这个错误:

神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

我的火车和测试样本

ensembleTrainSample <- sample(nrow(allClassifiers), nrow(allClassifiers)*0.7)
ensembleTestSample <- (1:nrow(allClassifiers))[!(1:nrow(allClassifiers))%in% ensembleTrainSample]

与您的其他问题类似,这是源于矩阵乘法的错误。 本质上,以下错误:

神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

表示您的矩阵没有与矩阵乘法匹配的维。 这就像尝试将4x4矩阵乘以10x10矩阵。 它根本行不通。

现在,出现此错误的原因是因为您忽略了文档中的某些内容。 如果查看?compute ,将会看到有关covariate参数的以下注释:

covariate   a dataframe or matrix containing the variables 
            that had been used to train the neural network.

这里的关键是VARIABLES ,而不是整个数据集也不是分类变量(您正在尝试预测这一点!)。 这又是有关infert数据集的示例。

library(neuralnet)
data(infert)

# fit your neuralnet model
net.infert <- neuralnet(case~parity+induced+spontaneous, infert)

net.pred <- compute(net.infert, infert[,c("case","parity","induced","spontaneous")])

神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

但是,如果仅包含用于创建模型的变量,则它可以正常工作而不会出错。

# no error
net.pred <- compute(net.infert, infert[,c("parity","induced","spontaneous")])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM