Nixtla / nixtlar

R SDK for TimeGPT
https://nixtla.github.io/nixtlar/
Apache License 2.0
9 stars 3 forks source link

Minimum length of time series for cross validation when using finetune? #4

Open vidarsumo opened 4 months ago

vidarsumo commented 4 months ago

I'm experimenting with nixtla_client_cross_validation(). When I'm using monthly data and some of the time series have few observations, I get an error when setting finetune_steps.

This works:

n_obs <- 37

# Create data
test_tbl <- tibble(
  unique_id = "id",
  ds = seq.Date(from = as.Date("2019-01-01"), length.out = n_obs, by = "month"),
  y = round(runif(n_obs, min = 10, max = 20))
)

timegpt_tscv <- nixtla_client_cross_validation(
  df         = test_tbl,
  h          = 12,
  id_col     = "unique_id",
  time_col   = "ds",
  target_col = "y",
  n_windows  = 1,
  finetune_steps = 10
)

This throws an error:

n_obs <- 36

# Create data
test_tbl <- tibble(
  unique_id = "id",
  ds = seq.Date(from = as.Date("2019-01-01"), length.out = n_obs, by = "month"),
  y = round(runif(n_obs, min = 10, max = 20))
)

timegpt_tscv <- nixtla_client_cross_validation(
  df         = test_tbl,
  h          = 12,
  id_col     = "unique_id",
  time_col   = "ds",
  target_col = "y",
  n_windows  = 1,
  finetune_steps = 10
)

Frequency chosen: MS
Error in `httr2::req_perform()`:
! HTTP 500 Internal Server Error.

Then I tried different frequency. Using weekly time series, even when I cut one of them so it's only 3 weeks long, I get no error.

walmart_tbl <- timetk::walmart_sales_weekly %>% 
  select(id, Date, Weekly_Sales) %>% 
  set_names("unique_id", "ds", "y")

# make one time series short
walmart_short_tbl <- walmart_tbl %>% 
  filter(unique_id == "1_1") %>% 
  tail(3) %>% 
  bind_rows(
    walmart_tbl %>% 
      filter(!unique_id == "1_1")
  )

timegpt_tscv <- nixtla_client_cross_validation(
  df         = walmart_short_tbl,
  h          = 12,
  id_col     = "unique_id",
  time_col   = "ds",
  target_col = "y",
  n_windows  = 1,
  freq = "W-FRI",
  finetune_steps = 10
)