R x-y中的错误:不一致数组

  • 本文关键字:不一致 数组 错误 x-y r
  • 更新时间 :
  • 英文 :


我正试图用以下数据集(小部分)在R中训练神经网络

      Age   Salary Mortrate Clientrate Savrate PartialPrate
 [1,]  62 2381.140    0.047       7.05     3.1            0
 [2,]  52 1777.970    0.047       6.10     3.1            0
 [3,]  53 2701.210    0.047       6.40     3.1            0
 [4,]  52 4039.460    0.047       7.00     3.1            0
 [5,]  56  602.240    0.047       6.20     3.1            0
 [6,]  43 2951.090    0.047       6.80     3.1            0
 [7,]  49 4648.860    0.047       7.50     3.1            0
 [8,]  44 3304.110    0.047       7.10     3.1            0
 [9,]  56 1300.000    0.047       6.10     3.1            0
[10,]  50 1761.440    0.047       6.95     3.1            0

如果我像上面那样尝试对小数据集执行此操作,代码会起作用,但如果我获取更多数据,则neuralnet()会给出错误:

Neuralnet error Error in x - y : non-conformable arrays. 

这个错误意味着什么?我该如何修复它?

代码:

trainingsoutput <- AllData$PartialPrepay
trainingdata <- cbind(AllData$LEEFTIJD, AllData$MEDSAL2, AllData$rate5Y,
                      AllData$CRate, AllData$SavRate, trainingsoutput)
dimnames(trainingdata) <- list(NULL, 
                               c("Age","Salary","Mortrate","Clientrate", 
                                 "Savrate","PartialPrate"))
nn <- neuralnet(PartialPrate ~ Age + Salary + Mortrate + Clientrate + Savrate,
                data = trainingdata ,hidden=3, err.fct="sse", threshold=0.01)

我刚刚遇到了同样的问题,当我从预测器中删除任何NAN(或用一些正常的默认值替换它们)时,这个问题似乎已经解决了。

错误消息描述:

短语Conformable arrays是线性代数术语,表示"可以合理地一起操作的数组"。R中的裸星号运算符(以及(+-/)执行逐元素乘法,也称为逐元素乘法。它们可以是不同的方向,但必须是相同的长度。

如何在R中重现此错误:

x = matrix(c(1, 2, 3))         #has dimension 3 1
y = matrix(c(1, 2))            #has dimension 2 1
e = x * y                      #Error in x * y : non-conformable arrays
e

两个矩阵或向量之间的星号运算符必须具有兼容的维度:

要解决上述问题,请确保矩阵具有兼容的尺寸:

x = matrix(c(1, 2, 3))
y = matrix(c(c(1, 2, 3)))
e = x * y
e

打印:

     [,1]
[1,]    1
[2,]    4
[3,]    9

重现此错误的其他方法:

matrix(1,2,3)    + matrix(1,2)       #Error, non-conformable arrays
matrix(1:6)      / matrix(1:5)       #Error, non-conformable arrays
matrix(c(1,2))   / matrix(5)         #Error, non-conformable arrays
matrix(c(1,2,3)) * matrix(c(1,2))    #Error, non-conformable arrays
matrix(c(1,2))   * matrix(c(1))      #Error, non-conformable arrays
matrix(c(1,2))   * matrix(1)         #Error, non-conformable arrays

确保使用类似的数据结构。如果您使用的是数组,请确保这两个变量都是数组。如果它们是数据帧,那么两者都应该是数据帧。

最新更新