macs2021
macs2021

Reputation: 85

Forecasting with fable package, Erro: `as_tsibble()` doesn't know how to handle the numeric class yet

I have been using the fable package for time series analysis and during the forecasting I have been getting this error: Erro: as_tsibble() doesn't know how to handle the numeric class yet.

My data is very big and it is a tsibble:

    bcUI Date      
   <dbl> <date>    
 1  11.0 2012-01-01
 2  26.4 2012-01-02
 3  24.9 2012-01-03
 4 121.  2012-01-04
 5  94.1 2012-01-05
 6 137.  2012-01-06
 7  53.7 2012-01-07
 8  45.2 2012-01-08
 9  19.4 2012-01-09
10  26.3 2012-01-10
... with 2,547 more rows

I am tryng to make 4 forecasting for 3 months (90 days, jan,feb and Mar), using 4 differnt methods and plotting them in the same graph. The code is:

bctsibble_fit = bctsibble %>%
  model(
    seasonal_naive=SNAIVE(bcUI),
    naive=NAIVE(bcUI),
    drift=RW(bcUI~drift()),
    mean=MEAN(bcUI)
  )

bctsibble_fc = bctsibble_fit %>%
  forecast(h=90)

bctsibble_fc %>%
  autoplot(bcUI,level=NULL)+
  labs(title ="Forecast"
       , x="")+
  theme_bw()+
  theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        axis.text.x = element_text(size = 8.5))

Thank you!

Upvotes: 0

Views: 1178

Answers (1)

Mitchell O&#39;Hara-Wild
Mitchell O&#39;Hara-Wild

Reputation: 2459

When using the autoplot(<fable>) function to produce a plot of your forecasts, you should provide the historical data in a tsibble format rather than a vector. Instead of bctsibble_fc %>% autoplot(bcUI,level=NULL), you should have bctsibble_fc %>% autoplot(bctsibble,level=NULL).


bctsibble_fc %>%
  autoplot(bctsibble,level=NULL)+
  labs(title ="Forecast"
       , x="")+
  theme_bw()+
  theme(panel.grid.major = element_blank(),panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        axis.text.x = element_text(size = 8.5))

Upvotes: 1

Related Questions