Hi all,
I'm trying to use Time series forecast for multiple columns at the same time...
Using below code..But it is giving same value for all future dates. Can someone please help?
Original data:
Date | Category | Qty |
---|---|---|
1/1/2019 | A | 123 |
1/2/2019 | A | 345 |
1/3/2019 | A | 123 |
1/4/2019 | A | 555 |
1/5/2019 | A | 756 |
1/6/2019 | A | 128 |
1/7/2019 | A | 192 |
1/8/2019 | A | 106 |
1/9/2019 | A | 113 |
1/10/2019 | A | 140 |
1/1/2019 | B | 234 |
1/2/2019 | B | 564 |
1/3/2019 | B | 568 |
1/4/2019 | B | 879 |
1/5/2019 | B | 453 |
1/6/2019 | B | 321 |
1/7/2019 | B | 345 |
1/8/2019 | B | 654 |
1/9/2019 | B | 675 |
1/10/2019 | B | 142 |
1/1/2019 | C | 978 |
1/2/2019 | C | 984 |
1/3/2019 | C | 901 |
1/4/2019 | C | 993 |
1/5/2019 | C | 876 |
1/6/2019 | C | 566 |
1/7/2019 | C | 599 |
1/8/2019 | C | 920 |
1/9/2019 | C | 856 |
1/10/2019 | C | 517 |
library(forecast)
library(fpp2)
View(df1)
#reshape and convert it to a proper time-series format like ts:
tsMat <- ts(reshape2::dcast(df1, Date~Category))
tsMat
View(tsMat)
output <- lapply(tsMat, function(x) forecast(auto.arima(x)))
lapply(tsMat, function(x) forecast(auto.arima(x),h=5))