【问题标题】:Why is this fitting model giving 1 model per df line为什么这个拟合模型为每条 df 线提供 1 个模型
【发布时间】:2021-12-19 12:23:49
【问题描述】:

在正常模型中拟合数据集,如下所示:

> head(total)
# A tsibble: 6 x 15 [1D]
# Key:       id [6]
  Date       Close Interest_Rate Consumer_Inflation `CPI(YOY)` `Wage_Index(QoQ)` `Wage_Index(YoY)` AiG_idx TD_Inflation CFTC_AUD_net_positions `RBA_Mean_CPI(Yo~ Commonwealth_Ba~
  <date>     <dbl>         <dbl>              <dbl>      <dbl>             <dbl>             <dbl>     <dbl>        <dbl>                  <dbl>             <dbl>            <dbl>
1 2009-04-01  69.4             0                  0          0                 0                 0         0            0                      0                 0                0
2 2009-04-02  71.6             0                  0          0                 0                 0         0            0                      0                 0                0
3 2009-04-03  71.0             0                  0          0                 0                 0         0            0                      0                 0                0
4 2009-04-06  71.0             0                  0          0                 0                 0         0            0                      0                 0                0
5 2009-04-07  71.6             3                  0          0                 0                 0         0            0                      0                 0                0
6 2009-04-08  71.1             3                  0          0                 0                 0         0            0                      0                 0                0

训练模型:

fit <- total_axy %>%
  model(
    fable::TSLM(Close)
    )

report(axy_fit)

正在训练

1-10 of 3,409 rows | 1-10 of 16 columns

每行 1 个模型!我该如何解决这个问题? 我只想要所有行的 1 个模型!!!

【问题讨论】:

  • model()来自什么包?
  • fpp3 ,出自《预测原理与实践3》一书

标签: r forecasting fable


【解决方案1】:

您每行获得一个模型,因为您的 key 设置为 id,我猜它设置为每行唯一的值。可以看到id有6行6个唯一值。

根据package website tsibble 有一个key 属性,它应该是:

一组定义随时间变化的观察单位的变量

要修复它,请尝试更改密钥或删除它。

一个例子:

library(dplyr)
library(tsibble)
library(fpp3)

total <- 
  tibble(
  Date = seq.Date(from = as.Date("2009-04-01"), to = as.Date("2009-04-08"), by = 1),
  Close = rnorm(length(Date))
) %>% 
  # Make a tsibble with no key
  as_tsibble(index = Date)

fit <- 
  total %>% 
  model(
    fable::TSLM(Close)
  )

report(fit)

这仅给出一个模型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2019-04-20
    • 2022-01-21
    • 2018-07-07
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多