R中的Neuralnet包有问题

时间:2016-10-31 16:08:37

标签: r machine-learning

我试图用包神经网络计算神经网络,以解决回归问题。我试图近似函数: f(x1,x2)= sqrt(x1)+ sin(x2)+ x1 * x2。

这是我的代码:

library(neuralnet)
library(scatterplot3d)
X1 <- as.data.frame(runif(1000, min = 0 , max = 100))
X2 <- as.data.frame(runif(1000, min = 0 , max = 100))
input <- cbind(X1,X2)
sortie <- sqrt(X1) + sin(X2) + X1*X2
donnee <- cbind(sortie,input)
colnames(donnee) <- c("sortie","entree1","entree2")

f <- as.formula(sortie ~ entree1 + entree2)
net.f <- neuralnet(f , donnee, hidden = c(10,10,10) ,linear.output = FALSE)

这里是查看神经网络输出的散点图的代码:

  abscisse1 <- 0:100
  abscisse2 <- 0:100
  net.abscisseformule <- compute(net.f , cbind(abscisse1,abscisse2))
  neuralsortie <-  c(net.abscisseformule$net.result)
  scatterplot3d(abscisse1,abscisse2,neuralsortie)

我很确定结果是错误的,因为散点图看起来不像函数f的散点图。我觉得这个问题来自于行

f <-as.formula(sortie ~ entree1 + entree2)

这是查看函数

的散点图的代码
x <- seq(0, 100, 1)
y <- seq(0, 100, 1)
z <- sqrt(x) + sin(y) +x*y
scatterplot3d(x,y,z)

这是f的图表 https://i.stack.imgur.com/HkpbG.png

这是神经网络输出的图表 https://i.stack.imgur.com/N38dd.png

有人可以给我一些建议吗?非常感谢 !

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。根据“统计学习要素”(Friedman,Tibshirani和Hastie)一书,在解决回归问题时,需要在神经网络的最后一层使用身份函数。这意味着输出是前一层的线性组合。为了使用R,需要设置&#34; linear.output&#34;为真,而不是假。

相关问题