我正在尝试使用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

最佳答案

建议您在馈入神经网络之前将数据标准化。如果您这样做,那么就很好了:

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?似乎有一些最详细的信息。

08-25 05:05