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

时间:2013-10-06 06:24:13

标签: r neural-network backpropagation

我正在尝试使用训练有素的反向传播神经网络在新数据集上使用神经网络包生成预测。我使用了'compute'函数,但最终得到的所有观察值都相同。我做错了什么?

# 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

1 个答案:

答案 0 :(得分:2)

我能够让以下工作:

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用于训练神经网络,使用反向传播,弹性反向传播(RPROP)与(Riedmiller,1994)或没有重量回溯(Riedmiller和Braun,1993)或Anastasiadis等人的改进的全局收敛版本(GRPROP)。 (2005年)。该功能允许通过自定义选择错误和激活功能进行灵活设置。此外,还实现了广义权重的计算(Intrator O.和Intrator N.,1993)。