【发布时间】:2023-03-17 18:36:01
【问题描述】:
我正在尝试使用包神经网络计算神经网络,以解决回归问题。我正在尝试近似函数: 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
有人可以给我一个建议吗?非常感谢 !
【问题讨论】:
-
请记住在您的代码中包含所有库语句。我认为您至少缺少 2 个。请同时显示您要比较的 2 个图。
标签: r machine-learning