R中的Neuralnet软件包大错误 [英] Neuralnet package in R big error

查看:155
本文介绍了R中的Neuralnet软件包大错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何使Neuronet包正常工作.我对我创建的数据及其结果进行了一些测试(大约50行数据和三列,第四列是我想要的结果,它是由简单的数学执行(例如将其他三列之和加起来)制成的),到目前为止效果很好.然后,我决定将该程序包应用于实际数据.我从此处 http://vincentarelbundock.github.io/Rdatasets/datasets.html <下载了mpg数据集/a>

I am trying to figure out how to make the neuralnet package to work. I did some tests with data I created and with their outcomes (about 50 rows of data and three columns with the fourth being the outcome I wanted and it was made from simple mathematical executions like summing the other three columns) and so far so good. Then I decided to apply the package on real data. I downloaded the mpg dataset from here http://vincentarelbundock.github.io/Rdatasets/datasets.html

我正在运行下面的代码:

I was running the code bellow:

net<- neuralnet(cty~displ+year+cyl+hwy,
                datain, hidden=3)

即使我有3个隐藏层,或8或18个隐藏层,错误也是相同的,并且从该数据量(234行)开始,程序包处理数据的时间相对较小:

Even if I have 3 hidden layers, or 8 or 18 the error is the same and the time that the package processes the data is relatively small from this amount of data (234 lines):

        Error Reached Threshold Steps
1 2110.173077    0.006277805853    54

对此有什么好的建议吗?

Any good advice for this?

推荐答案

我想这是一个缩放问题,您可以对其进行归一化或缩放. scalingnormalizing之间存在差异,它将影响您的结果,因此值得在SO上另外提出一个问题:

It's a scale problem i guess, you can normalize or scale it. There are differences between scaling and normalizing, it will affect your results and worths a separate question on SO:

norm.fun = function(x){ 
  (x - min(x))/(max(x) - min(x)) 
}

require(ggplot2) # load mpg dataset
require(neuralnet)

data = mpg[, c('cty', 'displ', 'year', 'cyl', 'hwy')]
data.norm = apply(data, 2, norm.fun)

net = neuralnet(cty ~ displ + year + cyl + hwy, data.norm, hidden = 2)

然后您可以对数据进行非规范化

Then you can denormalize the data

# restore data 
y.net = min(data[, 'cty']) + net$net.result[[1]] * range(data[, 'cty'])
plot(data[, 'cty'], col = 'red')
points(y.net)

data.scaled = scale(data)
net = neuralnet(cty ~ displ + year + cyl + hwy, data.scaled, hidden = 2)

# restore data 
y.sd = sd(data[, 'cty'])
y.mean = mean(data[, 'cty'])

y.net = net$net.result[[1]] * y.sd + y.mean
plot(data[, 'cty'], col = 'red')
points(y.net)

您还可以尝试 nnet 软件包,它非常快:

You can also try the nnet package, it's very fast:

require(nnet)

data2 = mpg
data2$year = scale(data2$year)
fit = nnet(cty ~ displ + year + cyl + hwy, size = 10, data = data2, linout = TRUE)
plot(mpg$cty)
points(fit$fitted.values, col = 'red')

这篇关于R中的Neuralnet软件包大错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆