简体   繁体   English

用神经网络在R中计算?

[英]compute with neural network in R?

all tuples in allClassifiers tuples are either 1 or 2 eg 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

I trained the ensembler 我训练了合奏者

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

but I am trying to use it to predict with this: 但是我试图用它来预测:

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

but I get this error: 但是我得到这个错误:

Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments 神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

my train and Test samples 我的火车和测试样本

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

Similar to your other question this is an error the stems from matrix multiplication. 与您的其他问题类似,这是源于矩阵乘法的错误。 In essence, the following error: 本质上,以下错误:

Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments 神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

means that your matrices don't have dimensions that match for matrix multiplication. 表示您的矩阵没有与矩阵乘法匹配的维。 It's like trying to multiply a 4x4 matrix by a 10x10 matrix. 这就像尝试将4x4矩阵乘以10x10矩阵。 it simply isn't going to work. 它根本行不通。

Now the reason you are getting this error is because you overlooked something in the documentation. 现在,出现此错误的原因是因为您忽略了文档中的某些内容。 If you look at ?compute you will see the following note about the covariate argument`: 如果查看?compute ,将会看到有关covariate参数的以下注释:

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

The key here is VARIABLES , not your entire dataset nor the classifier variable (you are trying to predict this!). 这里的关键是VARIABLES ,而不是整个数据集也不是分类变量(您正在尝试预测这一点!)。 Here is an example again with the infert dataset. 这又是有关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")])

Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments 神经元[[i]]%*%权重[[i]]中的错误:不一致的参数

But if I just include the variables I used to create the model it works without error. 但是,如果仅包含用于创建模型的变量,则它可以正常工作而不会出错。

# 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