[R] Reformatting output of Forecasts generated by mlp model

Paul Bernal p@ulbern@l07 @ending from gm@il@com
Thu Dec 20 16:11:20 CET 2018

Dear friends,

Hope you are doing great. I am using the multiple layer perceptron model
(provided in R´s mlp() function for time series forecasting, but I don´t
know how to reformat the output forecasts generated.

mydata <- dput(datframe$Transits)

> dput(datframe$Transits)
c(77L, 75L, 85L, 74L, 73L, 96L, 82L, 90L, 91L, 81L, 81L, 77L,
84L, 81L, 82L, 86L, 81L, 81L, 83L, 88L, 88L, 92L, 97L, 89L, 96L,
94L, 94L, 95L, 92L, 94L, 95L, 95L, 87L, 102L, 94L, 91L, 93L,
86L, 96L, 85L, 81L, 84L, 88L, 91L, 89L, 89L, 93L, 83L, 92L, 92L,
76L, 98L, 80L, 95L, 89L, 92L, 96L, 86L, 98L, 84L, 90L, 95L, 90L,
99L, 85L, 91L, 90L, 88L, 97L, 93L, 97L, 87L, 92L, 87L, 86L, 85L,
82L, 90L, 89L, 101L, 94L, 92L, 109L, 101L, 103L, 96L, 89L, 102L,
87L, 101L, 100L, 99L, 101L, 98L, 101L, 90L, 106L, 90L, 99L, 105L,
91L, 96L, 91L, 96L, 93L, 101L, 105L, 98L, 110L, 100L, 101L, 106L,
99L, 111L, 114L, 112L, 113L, 120L, 105L, 111L, 114L, 111L, 118L,
115L, 108L, 120L, 119L, 120L, 118L, 117L, 121L, 111L, 114L, 107L,
121L, 109L, 106L, 116L, 105L, 119L, 120L, 123L, 126L, 117L, 127L,
128L, 132L, 138L, 120L, 132L, 134L, 136L, 144L, 152L, 155L, 146L,
155L, 138L, 141L, 146L, 123L, 133L, 123L, 137L, 133L, 143L, 132L,
126L, 134L, 129L, 138L, 134L, 132L, 139L, 130L, 152L, 150L, 153L,
161L, 152L, 154L, 154L, 138L, 149L, 137L, 144L, 146L, 152L, 140L,
151L, 168L, 148L, 157L, 152L, 153L, 166L, 157L, 156L, 166L, 168L,
179L, 188L, 190L, 185L, 184L, 185L, 202L, 191L, 175L, 197L, 187L,
195L, 204L, 218L, 220L, 212L, 220L, 211L, 221L, 204L, 196L, 209L,
205L, 217L, 211L, 212L, 224L, 206L, 225L, 206L, 219L, 232L, 220L,
242L, 241L, 261L, 252L, 261L, 269L, 251L, 264L, 261L, 266L, 274L,
236L, 270L, 263L, 276L, 276L, 300L, 303L, 301L, 318L, 294L, 308L,
308L, 269L, 303L, 302L, 318L, 282L, 311L, 305L, 304L, 309L, 298L,
295L, 295L, 281L, 280L, 287L, 313L, 276L, 296L, 307L, 307L, 309L,
287L, 286L, 290L, 261L, 285L, 279L, 286L, 284L, 267L, 271L, 259L,
268L, 243L, 242L, 237L, 208L, 250L, 237L, 267L, 257L, 276L, 277L,
269L, 282L, 264L, 270L, 270L, 251L, 272L, 271L, 288L, 266L, 283L,
266L, 270L, 282L, 272L, 264L, 269L, 253L, 269L, 283L, 288L, 275L,
301L, 292L, 283L, 287L, 261L, 265L, 269L, 234L, 251L, 261L, 262L,
249L, 256L, 255L, 253L, 253L, 233L, 234L, 235L, 217L, 244L, 232L,
261L, 236L, 252L, 242L, 252L, 251L, 230L, 240L, 254L, 226L, 267L,
245L, 263L, 261L, 286L, 281L, 265L, 274L, 250L, 260L, 265L, 242L,
251L, 249L, 251L, 247L, 248L, 234L, 206L, 219L, 194L, 218L, 209L,
192L, 207L, 200L, 208L, 208L, 209L, 213L, 216L, 219L, 195L, 217L,
217L, 197L, 210L, 211L, 229L, 232L, 227L, 233L, 217L)

TransitsDat <- ts(mydata, start=(1985,10), end=c(2018,9), frequency=12)

Model <- mlp(TransitsDat)

ModelForecasts <- forecast(Model, h=10)

And the output I get is this:

           Jan         Feb         Mar         Apr         May
Jun         Jul Aug Sep         Oct         Nov         Dec
224.9970134 221.7932717 220.2698789
2019 223.8440115 219.3309631 221.5382052 221.5720276 222.0963057
223.8392450 224.0982199

But I would like to have the results in tabular form, where the first
column is the date with format mmm-yyyy (for example jan-2019) and the
second row are the actual forecasts.

Like this
Date           TransitForecast
Jan-2019     230
Feb-2019    217

Any guidance will be greatly appreciated,

Best regards,


	[[alternative HTML version deleted]]

More information about the R-help mailing list