Hi,
I’m having mayor issues with predict from the nnet package.
I’m training a neural network for forecasting. I trained the network with
info from 1995 to 2009 and I want to forecast month by month 2010.(the
network forecasts one month at a time).
Since I have to do iterative forecasting, im using predict several times
including, including the new forecast each time, but for some reason predict
doesn’t forecast after the first itereation.
Here is my code:
pronostico4=function(x,rezagosx,muestra, reps, tam, maxi,vo,net){
library(timeSeries)
library(nnet)
library(dummies)
x=as.timeSeries(x)
X=NULL
for (k in 1:length(rezagosx)) {
X=cbind(X, lag(diff(log(x)),rezagosx[k]))
}
pred=predict(net, X,type="raw")
print(sum(is.na(pred)))
pred[muestra]=diff(log(x))[muestra]
pred=exp(diffinv(pred[is.na(pred)==0],xi=log(vo)) )
muestra2=muestra
muestra2[max(which(muestra2==1))+1]=TRUE
print(length(pred))
print(sum(muestra2))
print(sum(is.na(X)))
x[muestra2]=pred[1:sum(muestra2)]
return(x)
}
muestra=(is.na(a[,"Precio.Promedio.Bolsa"])==0 &
a[,"año"]<2009)
pred=a[,"Precio.Promedio.Bolsa"]
pred[muestra==F]=NA
pred=as.timeSeries(pred)
X=NULL
for (k in 1:length(rezagosx)) {
X=cbind(X, lag(diff(log(pred)),rezagosx[k]))
}
net=nnet2(diff(log(pred)),X,muestra,reps,tam,maxi)
for (i in 1:12){
pred=pronostico4(pred,rezagosx,muestra,reps,tam,maxi,vo,net)
muestra[max(which(muestra==1))+1]=TRUE
}
Mauricio Romero
Quantil S.A.
Cel: 3112231150
"It is from the earth that we must find our substance; it is on the earth
that we must find solutions to the problems that promise to destroy all life
here"
[[alternative HTML version deleted]]