首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用适合于另一组的模型对某一组的预测结果

用适合于另一组的模型对某一组的预测结果
EN

Stack Overflow用户
提问于 2020-09-25 18:34:50
回答 1查看 150关注 0票数 1

我试图使用适合于一组时间序列的fable模型来预测另一组的时间序列:

代码语言:javascript
复制
library(dplyr)
library(fable)
library(feasts)
library(tsibble)
library(fabletools)

df <- data.frame(
    id = rep(c('A', 'B'), each = 5),
    date = seq(as.Date('2020-01-01'), by = "month", length.out = 10),
    y = rnorm(10)
)

train_tsbl <- as_tsibble(filter(df, id == 'A'), key = id, index = date)
test_tsbl <- as_tsibble(filter(df, id == 'B'), key = id, index = date)

model <- train_tsbl %>%
    model(lm = TSLM(y ~ trend()))

但是,当预测到与ID 'B‘相对应的" test“集- records时,forecast调用返回'B'的空结果--测试集。

代码语言:javascript
复制
> forecast(model, test_tsbl)
# A fable: 0 x 4 [?]
# Key:     id, .model [0]
# … with 4 variables: id <fct>, .model <chr>, date <date>, y <dist>

但是对于train_tsbl,如下所示:

代码语言:javascript
复制
> forecast(model, train_tsbl)
# A fable: 5 x 5 [1D]
# Key:     id, .model [1]
  id    .model date                   y  .mean
  <fct> <chr>  <date>            <dist>  <dbl>
1 A     lm     2020-01-01  N(0.19, 1.8)  0.191
2 A     lm     2020-02-01 N(-0.12, 1.5) -0.122
3 A     lm     2020-03-01 N(-0.42, 1.3) -0.416
4 A     lm     2020-04-01 N(-0.73, 1.5) -0.730
5 A     lm     2020-05-01    N(-1, 1.8) -1.03 

我似乎找不到任何指定到新ID的选项。这里发生什么事情?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-26 07:18:33

您使用id作为密钥,这意味着您为每个密钥安装了一个单独的模型。然而,您的培训数据不包含id==B,因此没有B模型。

很难知道你在这里期望什么。您想为B行使用什么模型?

如果要使用A模型,则用B替换A设置测试集。

代码语言:javascript
复制
> forecast(model, test_tsbl %>% mutate(id = 'A'))
# A fable: 5 x 5 [1D]
# Key:     id, .model [1]
  id    .model date            y .distribution 
  <chr> <chr>  <date>      <dbl> <dist>        
1 A     lm     2020-06-01 -0.100 N(-0.10, 0.32)
2 A     lm     2020-07-01 -0.217 N(-0.22, 0.42)
3 A     lm     2020-08-01 -0.338 N(-0.34, 0.56)
4 A     lm     2020-09-01 -0.459 N(-0.46, 0.73)
5 A     lm     2020-10-01 -0.575 N(-0.58, 0.93)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64069652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档