You are on page 1of 3

Greykite: A flexible, intuitive, and fast forecasting library | LinkedIn Eng... https://engineering.linkedin.com/blog/2021/greykite--a-flexible--intuitive...

excessive buffers. Better information about future traffic, combined with accurate site
capacity measurements, enables confident decision making. Since even a small
percentage of savings translates to a large reduction in total cost, accurate forecasts
have a big business impact. Forecasts enable continued, sustainable growth through
right-sized applications.

Algorithm design

Figure 1. Architecture diagram for Greykite library's main forecasting algorithm,


Silverkite

The Silverkite algorithm architecture is shown in Figure 1. The green parallelograms


represent model inputs, and the orange ovals represent model outputs. The user
provides the input time series and any known anomalies, events, regressors, or
changepoint dates. The model returns forecasts, prediction intervals, and diagnostics.

The blue rectangles represent computation steps of the algorithm, decomposed into
two phases:

Phase (1): the conditional mean model.

Phase (2): the volatility/error model.

In (1), a model is utilized to predict the metric of interest, and in (2), a volatility model
is fit to the residuals. This choice helps us with flexibility and speed, because
integrated models are often more susceptible to poor tractability (convergence issues
for parameter estimates) or divergence issues in the simulated future values
(predictions).

Phase (1) can be broken down into these steps:

(1.a) Extract raw features from timestamps, events data, and history of the series
(e.g., hour, day of week);

(1.b) Transform the features to appropriate basis functions (e.g., Fourier series
terms for various time scales);

(1.c) Apply a changepoint detection algorithm to the data to discover changes in


the trend and seasonality over time;

(1.d) Apply an appropriate machine learning algorithm to fit the features from
(1.b) and (1.c) (depending on the objective).

3 of 14 8/7/21, 12:56 AM
Greykite: A flexible, intuitive, and fast forecasting library | LinkedIn Eng... https://engineering.linkedin.com/blog/2021/greykite--a-flexible--intuitive...

The purpose of Step (1.b) is to transform the features into a space which can be used
in “additive” models when interpretability is needed. For Step (1.d), we recommend
explicit regularization-based models such as Ridge or Lasso. Note that if the objective
is to predict peaks, quantile regression or its regularized versions are desirable
choices. In the next sections, we provide more details on how these features are built
to capture various properties of the series.

In Phase (2), a simple conditional variance model can be fitted to the residuals, which
allows for the volatility to be a function of specified factors, e.g., day of the week. 

Case studies

To make the benefits of this design concrete, we illustrate with a few examples from
public datasets.

Time-varying trend and seasonality


It is very common to see time series with trend or seasonality patterns that change
over time.

Figure 2. Trend and seasonality changepoints in bike-sharing data

For example, Figure 2 shows the number of shared bike rides in Washington, D.C.,
from 2011 to 2019 at an hourly frequency. By inspecting this figure and other
aggregated trend plots, you can observe some indications of changes in trend
patterns. Silverkite allows the user to specify the changepoint locations or request
automatic trend changepoint and seasonality changepoint detection.

Automatic changepoint detection works as follows: For trend changepoints, we first


aggregate the time series into a coarser time series to eliminate short-term
fluctuations (which are captured by other features, such as holidays). For example,
daily data can be aggregated into weekly data to weaken the effect of holidays. In the
next step, a large number of potential trend changepoints are placed evenly over the
whole time period, except a time window at the end of the time series. We avoid
placing changepoints near the end of the time series to prevent extrapolating trend
changes based on limited data (an example of over-fitting in time series context).
Then we apply the Adaptive Lasso (Zou 2006) algorithm to shrink insignificant
potential trend changepoints. In the Adaptive Lasso regression problem, we fit the
aggregated time series with the potential trend changepoints and yearly seasonality
Fourier series, which is sufficient for capturing the long-term trend pattern:

aggregated_timeseries ~ growth + potential_trend_changepoints + yearly

4 of 14 8/7/21, 12:56 AM
Greykite: A flexible, intuitive, and fast forecasting library | LinkedIn Eng... https://engineering.linkedin.com/blog/2021/greykite--a-flexible--intuitive...

seasonality

The reason for choosing Adaptive Lasso over Lasso (Tibshirani 1996) is that, in our
experience, the latter over-shrinks significant changepoints’ coefficients to reach the
desired sparsity level.

Finally, the detected changepoints are used to construct piecewise growth basis
functions. For example, instead of a single linear trend, the growth can be piecewise
linear by allowing the slope to change at the detected points. Mathematically, if the
original growth term is f(t), e.g., f(t)=t, after detecting change points t1, …, tK, the
growth function will be of the form

To allow for changes in seasonality, Silverkite constructs basis functions that allow the
seasonal effect to change in both shape and magnitude with time. Silverkite also
allows for automatically detecting seasonality changepoints with the following
regression model:

De-trended_timeseries ~ Σcomponent  seasonality +


potential_seasonality_changepoints

Repeated events/holidays
It is important to capture the effect of repeated events such as holidays. Silverkite
constructs indicator variables to use as basis functions for the holidays. These
variables take the value 1 during the event, and 0 otherwise.

Seasonal effects can be disrupted by events, especially important holidays with a


large impact on the time series of interest. For example, in Figure 3 below, the daily
seasonality pattern is different on weekends (unimodal) and weekdays (bimodal). The
reason is that, while people tend to use bikes for commuting during weekdays, they
tend to use bikes for leisure on weekends. Silverkite uses interactions to handle these
in the model. These allow for any arbitrary deviation from the “regular” times, not only
simple mean-shifts during the event.

Figure 3. Silverkite captures different daily seasonality patterns on weekdays and


weekends

5 of 14 8/7/21, 12:56 AM

You might also like