business-science / modeltime.gluonts

GluonTS Deep Learning with Modeltime
https://business-science.github.io/modeltime.gluonts/
Other
39 stars 9 forks source link

New Model: DeepAR Torch #30

Closed mdancho84 closed 3 years ago

mdancho84 commented 3 years ago

Add support for Torch version of DeepAR, available in GluonTS 0.8.0. https://github.com/awslabs/gluon-ts/pull/1460/files

mdancho84 commented 3 years ago

Initial Torch DeepAR is implemented in modeltime using: deep_ar() %>% set_engine("torch")

Key References

Example

# Requires modeltime >= 0.6.1.9000

library(modeltime.gluonts)
library(tidymodels)
library(tidyverse)
library(timetk)

splits <- walmart_sales_weekly %>%
    time_series_split(
        assess     = 26,
        cumulative = TRUE
    )
#> Using date_var: Date
#> Data is not ordered by the 'date_var'. Resamples will be arranged by `Date`.
#> Overlapping Timestamps Detected. Processing overlapping time series together using sliding windows.

model_fit_deepar_torch <- deep_ar(
    id                    = "id",
    freq                  = "W",
    prediction_length     = 26,
    lookback_length       = 52*2,
    epochs                = 10,
    scale                 = TRUE
) %>%
    set_engine("torch") %>%
    fit(Weekly_Sales ~ Date + id, training(splits))

modeltime_table(
    model_fit_deepar_torch
) %>%
    modeltime_calibrate(
        new_data = testing(splits),
        id       = "id"
    ) %>%
    modeltime_forecast(
        new_data      = testing(splits),
        actual_data   = walmart_sales_weekly,
        conf_interval = 0.95,
        conf_by_id    = TRUE
    ) %>%
    group_by(id) %>%
    plot_modeltime_forecast(
        .interactive = FALSE,
        .facet_ncol  = 2
    )

Created on 2021-07-14 by the reprex package (v2.0.0)

Shafi2016 commented 3 years ago

Great!! Can we add external regressors to DeepAR model? Are you thinking to add DeepVAR to Modeltime gluonts or with Torch.?

mdancho84 commented 3 years ago

Not yet. We will investigate external regressors more soon.

Shafi2016 commented 3 years ago

Thanks, @mdancho84