* * Neural network example from pp 180 * open data ch04_ibm_m(26-99).txt calendar(m) 1926 data(format=free,org=columns) 1926:1 1999:12 ibmln * * Benchmark - use mean of data through 1997:12 * stats ibmln * 1997:12 set benchfore 1998:1 1999:12 = %mean * @uforeerrors ibmln benchfore * * AR(1) model * linreg(define=ar1eq) ibmln * 1997:12 # constant ibmln{1} * * Out-of-sample static (one step) forecasts for the AR(1) * uforecast(equation=ar1eq,static) ar1fore 1998:1 1999:12 @uforeerrors ibmln ar1fore * * Train the neural net. This sets an R**2 target of .10. This is probably * unachievable, but with only two hidden layers, it's unlikely that we * have to fear overfitting. * nnlearn(rsquared=.10,iters=100000,hidden=2,direct,save=nnmodel) * 1997:12 # ibmln{1 2 3} # ibmln * * Out-of-sample static forecasts for the neural net. Note that these are the * only types of forecasts that the neural net can produce (easily). To do * multiple step forecasts, you would need to loop over a series of one step * forecasts and feed the forecasts back into the series. * nntest 1998:1 1999:12 nnmodel # ibmln{1 2 3} # nnfore @uforeerrors ibmln nnfore