Reputation: 2627
I'm using test_forecast
and I have my code setup like this
df_train <- df[1:20]
df_test <- df[21:nrow(df)]
test_forecast(actual = df,
forecast.obj = forecast,
train = df_train,
test = df_test)
Every row in the df is accounted for in df train and df test.
But, it gives me this error
Error in test_forecast(actual = df, forecast.obj = forecast, :
The length of the train and test sets are different from the length of the actual set
df
is a data table, but I also tried this converting all the objects to data frames and that didn't work
Upvotes: 0
Views: 500
Reputation: 41260
I tried with a data frame and a data table and got exactly the same error message.
After reading carefully test_forecast
documentation, I found :
actual: The full time series object (supports "ts", "zoo" and "xts" formats).
The conclusion is that test_forecast
isn't supposed to work with data.frames / data.tables.
As you didn't provide the data you're using, I tried this example which worked:
library(TSstudio)
ts <- USgas
ts_par <- ts_split(ts, sample.out = 20)
train <- ts_par$train
test <- ts_par$test
ts_info(train)
ts_info(test)
library(forecast)
md <- tslm(train ~ season + trend)
fc <- forecast(md, h = 20)
test_forecast(actual = ts,
forecast.obj = fc,
test = test)
Another important point is that you shouldn't subset a timeseries as you would do with a data.table, because it becomes numeric
, so that it won't work with test_forecast
:
class(USgas[1:20])
[1] "numeric"
Upvotes: 1