我正在尝试使用neuralnet()函数来预测负载数据,但是,当我尝试使用forecast()函数时,我收到了错误: Error in is.constant(y):(list) object cannot be coerced to type 'double‘
我的数据如下:
date temperature load weekday month weekend day
1 2010-01-01 -28 256131 5 01 0 1
2 2010-01-02 -24 277749 6 01 1 2
3 2010-01-03 -53 264166 0 01 1 3
4 2010-01-04 -42 319847 1 01 0 4
5 2010-01-05 -17 321376 2 01 0 5并且是结构化的:
str(NLtrain)
'data.frame': 2191 obs. of 7 variables:
$ date : POSIXct, format: "2010-01-01" "2010-01-02" "2010-01-03" ...
$ temperature: num -28 -24 -53 -42 -17 -45 -43 -42 -25 -11 ...
$ load : num 256131 277749 264166 319847 321376 ...
$ weekend : num 0 1 1 0 0 0 0 0 1 1 ...
$ weekday : int 5 6 0 1 2 3 4 5 6 0 ...
$ month : chr "01" "01" "01" "01" ...
$ day : int 1 2 3 4 5 6 7 8 9 10 ...我使用的代码如下:
loadts <- ts(NLtrain$load, frequency=7, start = c(2010,1,1))
nnvar = NLtrain$weekday+NLtrain$day+NLtrain$temperature
nn = neuralnet(loadts~nnvar,
data = NLtrain, hidden = 3,
linear.output =FALSE)
forecast(nn)我做错了什么?
提前感谢
发布于 2017-04-05 19:16:28
您为neuralnet()定义公式的方式不正确。"nnvar“变成了一个向量,就像你解释的那样。它是列的总和。使用以下方法
nnvar<-as.formula(loadts~weekday+day+temperature)
nn=neuralnet(nnvar,data=NLtrain,hidden=3,linear.output=F)此外,由于loadts中的值不在(0,1)的区间内,我认为您不应该使用linear.output=F,因为在这种情况下,逻辑函数变成激活函数,并且您的值被限制为0-1
https://stackoverflow.com/questions/43227754
复制相似问题