business-science / modeltime.gluonts

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

GP Forecaster: Add Gaussian Process Forecast Model #29

Closed mdancho84 closed 3 years ago

mdancho84 commented 3 years ago

Integrate the Gaussian Process Estimator from GluonTS. https://ts.gluon.ai/api/gluonts/gluonts.model.gp_forecaster.html

mdancho84 commented 3 years ago

GP Forecaster is implemented in modeltime.gluont >= 0.2.2.900.

Example

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.

# * GP Forecaster -----

model_fit_gp <- gp_forecaster(
    id                    = "id",
    freq                  = "W",
    prediction_length     = 26,
    lookback_length       = 52*2,
    epochs                = 10,
    scale                 = TRUE
) %>%
    set_engine("gluonts_gp_forecaster", cardinality = 20) %>%
    fit(Weekly_Sales ~ Date + id, training(splits))

modeltime_table(
    model_fit_gp
) %>%
    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,
        .title       = "GP Forecaster"
    )

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