简体   繁体   English

R中的Neuralnet软件包出现问题

[英]Trouble with Neuralnet package in R

I'm trying to compute a neural network with the package neuralnet, to solve a regression problem. 我正在尝试使用包Neuronet计算一个神经网络,以解决回归问题。 I'm trying to approximate the function: f(x1,x2) = sqrt(x1) + sin(x2) + x1*x2. 我正在尝试近似函数:f(x1,x2)= sqrt(x1)+ sin(x2)+ x1 * x2。

here is my code: 这是我的代码:

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)

here is the code to look at the scatterplot of the outputs of the neural networks: 这是查看神经网络输出散点图的代码:

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

I'm pretty sure that the result is wrong because the scatterplot doesn't looks like the scatterplot of the function f. 我很确定结果是错误的,因为散点图看起来不像函数f的散点图。 I thonk that the problem comes from the line 我认为问题出在线

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

here is the code to look at the scatterplot of the function 这是查看函数散点图的代码

x <- seq(0, 100, 1)
y <- seq(0, 100, 1)
z <- sqrt(x) + sin(y) +x*y
scatterplot3d(x,y,z)

this is the graph of f https://i.stack.imgur.com/HkpbG.png 这是f的图https://i.stack.imgur.com/HkpbG.png

this is the graph of the outputs of the neuralnet https://i.stack.imgur.com/N38dd.png 这是神经网络的输出图https://i.stack.imgur.com/N38dd.png

Can somebody give me a piece of advice ? 有人可以给我一些建议吗? Many Thanks ! 非常感谢 !

I find the answer to my question. 我找到了我问题的答案。 According to the book The Elements of Statistical Learning (by Friedman,Tibshirani and Hastie), when solving a regression problem it is required to use the identity function in the last layer of the neural network. 根据《统计学习的要素》一书(Friedman,Tibshirani和Hastie的著作),在解决回归问题时,需要在神经网络的最后一层使用身份函数。 Which mean that the output is a linear combination of the previous layer. 这意味着输出是上一层的线性组合。 In order to do so with R, it is required to set "linear.output" to TRUE and not FALSE. 为了使用R进行此操作,需要将“ linear.output”设置为TRUE而不是FALSE。

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

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