r - 使用 R 上的反向传播神经网络模型生成预测会为所有观察返回相同的值

标签 r neural-network backpropagation

我正在尝试使用经过训练的反向传播神经网络在新数据集上使用神经网络包来生成预测。我使用了“计算”功能,但最终所有观察结果都得到相同的值。我做错了什么?

# the data
Var1 <- runif(50, 0, 100)
sqrt.data <- data.frame(Var1, Sqrt=sqrt(Var1))

# training the model
backnet = neuralnet(Sqrt~Var1, sqrt.data, hidden=2, err.fct="sse", linear.output=FALSE, algorithm="backprop", learningrate=0.01)

print (backnet)

Call: neuralnet(formula = Sqrt ~ Var1, data = sqrt.data, hidden = 2,     learningrate = 0.01, algorithm = "backprop", err.fct = "sse",     linear.output = FALSE)

1 repetition was calculated.

        Error Reached Threshold Steps
1 883.0038185    0.009998448226  5001

valnet = compute(backnet, (1:10)^2)

summary (valnet$net.result)

      V1           
Min.   :0.9998572  
1st Qu.:0.9999620  
Median :0.9999626  
Mean   :0.9999505  
3rd Qu.:0.9999626  
Max.   :0.9999626  

print (valnet$net.result)

         [,1]
[1,] 0.9998572272
[2,] 0.9999477241
[3,] 0.9999617930
[4,] 0.9999625684
[5,] 0.9999625831
[6,] 0.9999625831
[7,] 0.9999625831
[8,] 0.9999625831
[9,] 0.9999625831
[10,] 0.9999625831

最佳答案

我能够使以下内容发挥作用:

library(neuralnet)

# the data
Var1 <- runif(50, 0, 100)
sqrt.data <- data.frame(Var1, Sqrt=sqrt(Var1))

# training the model
backnet = neuralnet(Sqrt~Var1, sqrt.data, hidden=10, learningrate=0.01)

print (backnet)


Var2<-c(1:10)^2

valnet = compute(backnet, Var2)

print (valnet$net.result)

返回:

     [,1]
[1,] 0.9341689395
[2,] 1.9992711472
[3,] 3.0012823496
[4,] 3.9968226732
[5,] 5.0038316976
[6,] 5.9992936957
[7,] 6.9991576925
[8,] 7.9996871591
[9,] 9.0000849977
[10,] 9.9891334545

根据neuralnet reference manual ,该包的默认训练算法是反向传播:

neuralnet is used to train neural networks using backpropagation, resilient backpropagation (RPROP) with (Riedmiller, 1994) or without weight backtracking (Riedmiller and Braun, 1993) or the modified globally convergent version (GRPROP) by Anastasiadis et al. (2005). The function allows flexible settings through custom-choice of error and activation function. Furthermore the calculation of generalized weights (Intrator O. and Intrator N., 1993) is implemented.

关于r - 使用 R 上的反向传播神经网络模型生成预测会为所有观察返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19206052/

相关文章:

python - 在 `tf.py_func` 的输入函数中返回多个值

r - 在 R 中运行简单的 'rename' 函数时出现错误消息

r - 在ggplot2中添加x和y轴标签

r - 在一小时内改变下一个唯一值并扩展和聚合

python - 如果用于梯度更新的索引叶变量如何解决就地操作错误?

machine-learning - CNN中的滤波器数量是多少?

R - 神经网络 - 传统的反向传播看起来很奇怪

r - 从 RStudio : 在 RPub 中发布时出错

javascript - 过度拟合神经网络的最佳方法是什么?

machine-learning - 以编程方式执行梯度计算