【发布时间】:2020-06-11 21:57:41
【问题描述】:
在 R 神经网络包中,隐藏神经元的单个数字参数和向量参数有什么区别?例如隐藏 = 100 与隐藏 = c(100,50)
【问题讨论】:
标签: r machine-learning deep-learning neural-network data-science
在 R 神经网络包中,隐藏神经元的单个数字参数和向量参数有什么区别?例如隐藏 = 100 与隐藏 = c(100,50)
【问题讨论】:
标签: r machine-learning deep-learning neural-network data-science
你用它来提供 2 个信息,层数,也就是向量的长度,以及每层的神经元数量。
所以在你的问题中,neuralnet(..hidden=100) 表示 1 层有 100 个神经元,而 neuralnet(..hidden=c(100,50)) 表示 2 层,第 1 层 100 和第 2 层 50。
我们可以通过查看包含估计的连接权重的结果矩阵来看到这一点:
fit = neuralnet(Species == "setosa" ~ ., iris, linear.output = FALSE,hidden=2)
fit$result.matrix
[,1]
error 0.008141255
reached.threshold 0.008900248
steps 48.000000000
Intercept.to.1layhid1 -0.996032931
Sepal.Length.to.1layhid1 0.433339769
Sepal.Width.to.1layhid1 -1.178668127
Petal.Length.to.1layhid1 -0.483878954
Petal.Width.to.1layhid1 4.399508265
Intercept.to.1layhid2 1.764932246
Sepal.Length.to.1layhid2 -0.748650261
Sepal.Width.to.1layhid2 3.602604148
Petal.Length.to.1layhid2 -2.226669079
Petal.Width.to.1layhid2 -3.210541627
Intercept.to.Species == "setosa" -1.422643815
1layhid1.to.Species == "setosa" -3.596971312
1layhid2.to.Species == "setosa" 6.205140270
所以你在该层中只有 1 层和 2 个隐藏神经元,它们连接到变量和输出层。
如果你这样做:
fit = neuralnet(Species == "setosa" ~ ., iris, linear.output = FALSE,hidden=c(2,1))
fit$result.matrix
[,1]
error 0.010978699
reached.threshold 0.007306809
steps 92.000000000
Intercept.to.1layhid1 4.616674345
Sepal.Length.to.1layhid1 3.342501151
Sepal.Width.to.1layhid1 4.367109042
Petal.Length.to.1layhid1 5.385330435
Petal.Width.to.1layhid1 1.402765434
Intercept.to.1layhid2 -3.828104421
Sepal.Length.to.1layhid2 1.013023746
Sepal.Width.to.1layhid2 -6.037198731
Petal.Length.to.1layhid2 3.705741605
Petal.Width.to.1layhid2 7.993464809
Intercept.to.2layhid1 -2.075821677
1layhid1.to.2layhid1 -2.550031126
1layhid2.to.2layhid1 9.393164468
Intercept.to.Species == "setosa" 4.146671533
2layhid1.to.Species == "setosa" -8.957645357
它与之前类似,只是现在您有一个带有一个神经元的第二层,并且它连接到输出层。
【讨论】: