如何解决火车和测试装置的长度与实际装置的长度不同
我正在使用test_forecast
,并且我的代码设置如下
df_train <- df[1:20]
df_test <- df[21:nrow(df)]
test_forecast(actual = df,forecast.obj = forecast,train = df_train,test = df_test)
在df训练和df测试中,df中的每一行都占了
。但是,它给了我这个错误
Error in test_forecast(actual = df,:
The length of the train and test sets are different from the length of the actual set
df
是一个数据表,但我也尝试过将所有对象都转换为数据帧,但这没用
解决方法
我尝试了一个数据框和一个数据表,并得到了完全相同的错误消息。
仔细阅读test_forecast
documentation后,我发现:
实际:完整时间序列对象(支持“ ts”,“ zoo”和“ xts”格式)。
结论是test_forecast
不应该用于data.frames / data.tables。
由于您没有提供正在使用的数据,因此我尝试了this example,该方法可以有效:
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)
另一个重要的一点是,您不应该像对data.table那样对时间序列进行子集化,因为它变成了numeric
,因此它不适用于test_forecast
:>
class(USgas[1:20])
[1] "numeric"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。