【问题标题】:R - neuralnet - Traditional backprop seems strangeR - 神经网络 - 传统的反向传播似乎很奇怪
【发布时间】:2016-08-19 03:57:18
【问题描述】:

我正在尝试neuralnet 包中的不同算法,但是当我尝试传统的backprop 算法时,结果非常奇怪/令人失望。几乎所有的计算结果都是~.33???我假设我必须错误地使用算法,就好像我使用默认的 rprop+ 运行它一样,它确实区分了样本。当然,正常的反向传播并没有那么糟糕,特别是如果它能够如此快速地收敛到提供的阈值。

library(neuralnet)
data(infert)

set.seed(123)
fit <- neuralnet::neuralnet(formula = case~age+parity+induced+spontaneous, 
                            data = infert, hidden = 3, 
                            learningrate = 0.01, 
                            algorithm =  "backprop", 
                            err.fct = "ce", 
                            linear.output = FALSE,
                            lifesign = 'full', 
                            lifesign.step = 100)

preds <- neuralnet::compute(fit, infert[,c("age","parity","induced","spontaneous")])$net.result

summary(preds)
       V1           
 Min.   :0.3347060  
 1st Qu.:0.3347158  
 Median :0.3347161  
 Mean   :0.3347158  
 3rd Qu.:0.3347162  
 Max.   :0.3347286  

这里的某些设置应该不同吗?

示例默认神经网络

set.seed(123)
fit <- neuralnet::neuralnet(formula = case~age+parity+induced+spontaneous, 
                            data = infert, hidden = 3, 
                            err.fct = "ce", 
                            linear.output = FALSE,
                            lifesign = 'full', 
                            lifesign.step = 100)

preds <- neuralnet::compute(fit, infert[,c("age","parity","induced","spontaneous")])$net.result

summary(preds)
       V1           
 Min.   :0.1360947  
 1st Qu.:0.1516387  
 Median :0.1984035  
 Mean   :0.3346734  
 3rd Qu.:0.4838288  
 Max.   :1.0000000 

【问题讨论】:

    标签: r neural-network backpropagation


    【解决方案1】:

    建议您在输入神经网络之前对数据进行标准化。如果你这样做,那么你很高兴:

    library(neuralnet)
    data(infert)
    
    set.seed(123)
    infert[,c('age','parity','induced','spontaneous')] <- scale(infert[,c('age','parity','induced','spontaneous')])
    fit <- neuralnet::neuralnet(formula = case~age+parity+induced+spontaneous, 
                                data = infert, hidden = 3, 
                                learningrate = 0.01, 
                                algorithm =  "backprop", 
                                err.fct = "ce", 
                                linear.output = FALSE,
                                lifesign = 'full', 
                                lifesign.step = 100)
    
    preds <- neuralnet::compute(fit, infert[,c("age","parity","induced","spontaneous")])$net.result
    summary(preds)
           V1            
     Min.   :0.02138785  
     1st Qu.:0.21002456  
     Median :0.21463423  
     Mean   :0.33471568  
     3rd Qu.:0.47239818  
     Max.   :0.97874839  
    

    实际上有一些关于 SO 处理这个问题的问题。 Why do we have to normalize the input for an artificial neural network? 似乎有一些最详细的信息。

    【讨论】:

    • 有趣,我应该知道缩放。谢谢你。您知道为什么rprop+ 算法能够在默认情况下处理此问题而无需缩放?
    • 我不知道 - 我想它在代码中的某个地方是默认完成的,但我不知道为什么会有所不同。
    • 很公平,感谢您回答我的问题。我会四处寻找,也许稍后再问这个问题。
    猜你喜欢
    • 2015-03-03
    • 2012-02-21
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2020-06-20
    • 2013-04-26
    相关资源
    最近更新 更多