library(fable, fabletools, fable.prophet)
ddsmp <- na.omit(dsmp) |> 
   (function(df) df |> 
      dplyr::mutate(
        sq = 1:n(), 
        date = as_date(index), 
        quarter = quarter(index), 
        month = month(index), 
        wkdays = weekdays(index), 
        wk_1m = rep(1:7200, nrow(df)/7200), 
        dy_1m = rep(1:1440, nrow(df)/1440), 
        hr_1m = rep(1:60, nrow(df)/60)) |> 
      dplyr::select(index, year, quarter, month, 
                    week, wkdays, wk_1m, dy_1m, hr_1m, 
                    sq, date, close) |> 
      as_tsibble(index = index)
     )()
✓ 1.2 GiB [master*]> timeID <- unique(ddsmp$date)
✓ 1.2 GiB [master*]> bse <- ddsmp[ddsmp$year == 2016,]$date[1] #"2016-01-04" #1st trading date in 2nd year
✓ 1.2 GiB [master*]> timeID %<>% .[. >= bse]
✓ 1.2 GiB [master*]> #timeID %<>% .[. >= as_date('2016-01-04')]
✓ 1.2 GiB [master*]> vrb <- 1200 #1200 observations
✓ 1.2 GiB [master*]> frb <- 1
✓ 1.2 GiB [master*]> i   <- 1
✓ 1.2 GiB [master*]> 
✓ 1.2 GiB [master*]> train <- ddsmp |> 
     (function(df) 
         filter(df, date < timeID[i]) |> 
         tail(vrb))()
✓ 1.2 GiB [master*]> 
✓ 1.2 GiB [master*]> train <- train |> 
     as_tsibble(key = c(close, quarter, month, week, wkdays), index = index)
✓ 1.2 GiB [master*]> 
✓ 1.2 GiB [master*]> fit <- train |> 
   model(
     ets = ETS(close), 
     #ets_bc = ETS(box_cox(close, 0.3)),
     arima = ARIMA(close), 
     rw = RW(close), 
     rw_df = RW(close ~ drift()), 
     naive = NAIVE(close), 
     snaive = SNAIVE(close))
Warning: Seasonal periods (`period`) of length greather than 24 are not supported by ETS. Seasonality will be ignored.
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning in is.na(y) :
  is.na() applied to non-(list or vector) of type 'closure'
Warning: 2 errors (1 unique) encountered for ets
[2] invalid 'type' (closure) of argument

Warning: 2 errors (1 unique) encountered for arima
[2] object is not a matrix

Warning: 2 errors (1 unique) encountered for rw
[2] object is not a matrix

Warning: 2 errors (1 unique) encountered for rw_df
[2] object is not a matrix

Warning: 2 errors (1 unique) encountered for naive
[2] object is not a matrix

Warning: 2 errors (1 unique) encountered for snaive
[2] object is not a matrix

✓ 1.2 GiB [master*]> 
✓ 1.2 GiB [master*]> fc <- fit |> 
   fabletools::forecast(h = frb)
New names:
* close -> close...1
* close -> close...8
Error: Can't subset columns that don't exist.
x Column `close` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
x 1.2 GiB [master*]> fc <- fit |> 
     forecast(h = frb)
New names:
* close -> close...1
* close -> close...8
Error: Can't subset columns that don't exist.
x Column `close` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
x 1.2 GiB [master*]> 
x 1.2 GiB [master*]> ## accuracy
x 1.2 GiB [master*]> fc |> fabletools::accuracy(train)
Error in fabletools::accuracy(fc, train) : object 'fc' not found

fable, fabletools, fable.prophet这程序包。

    ryo 你这个玩的高大上啊,就是看着有点累,我看了半天仍旧是云里雾里的,你这个代码要是能进一步整理下,再增加一些必要的说明就好了。

    • ryo 回复了此帖
      2 个月 后

      tctcab
      '任何帖'? 小鹏?🐴🌉? 丁丁? 哪位?
      不是我的错,因为不姓刘或张
      刘/张冠黄戴,最佳导演刘张倆

      然后tidyverts如果可以嵌入bayesian, hmm, lstm models就完美了

      https://d.cosx.org/d/1553-1553

      1.1 错误的发帖姿势

      以下社区礼仪希望大家遵守:

      不要特意强调自己是新手,也不要加急;我们只关心问题能否问好,是否是新手、是否着急,与别人是否会回答问题无关。