3.3.3 Build Model

To build a model using time series data, apply the Exponential Smoothing algorithm to the proxy object ESM_SH_DATA created during the exploratory stage.

Oracle provides the Exponential Smoothing algorithm specifically for time series forecasting.

Exponential Smoothing is a forecasting technique that assigns exponentially decreasing weights to past observations. It is a type of moving average method. The Exponential Smoothing Model (ESM) includes components such as trend and seasonality, which can be modeled in either additive or multiplicative forms.
  • Trend refers to the long-term increase or decrease in the data over time. It captures the general direction or movement of the series, whether upward, downward, or stable.
  • Seasonality refers to regular, repeating patterns or cycles in the data that occur at fixed intervals, such as daily, monthly, or quarterly fluctuations caused by factors like holidays, weather, or business cycles.

In the additive form, the amplitude of variation (the size of the repeating seasonal fluctuations) is independent of the overall level of the time series, whereas in the multiplicative form, the seasonal variation changes proportionally with the level. Here, level refers to the baseline value or the underlying magnitude of the time series at a given point in time. This suggests a multiplicative model, where seasonal fluctuations are proportional to the level of the series—larger when the overall values are high and smaller when the values are low. Additive models assume that the error (or noise), trend, and seasonality are linear components. These components combine in a recursive way to form the final model.

To build a model using a supervised learning approach, it is common to split the dataset into training and test sets. However, time series modeling differs from classification and regression in that it predicts the next value in a series based on the preceding items in the series. In this case, splitting the dataset is unnecessary because the model always forecasts the current value using only past data. Although it may appear that the model is trained and tested on the same data, each forecast is based solely on prior time points.

In this use case, you will use the proxy object ESM_SH_DATA to build the Exponential Smoothing model.

  1. To get help on the Exponential Smoothing Model (ESM), run the following script:
    %r
     
    help(ore.odmESM)

    The output of help(ore.odmESM) is the function reference for the ore.odmESM. It guides you on how to use it to build exponential smoothing models for time series forecasting using in-database analytics in Oracle. This is helpful for learning the syntax, understanding parameters, and seeing example usage.

  2. Create a Holt-Winters model using the quarterly setting. The Holt-Winters model is a way to predict future values in a time series by looking at patterns like trends (overall direction) and seasonality (regular ups and downs). It updates its predictions step-by-step using only past data, never looking ahead.

    To build the model using the ESM_SH_DATA proxy object, run the following statement:

    This script deletes any existing model named ESM_SALES_FORECAST_1, then trains a Holt-Winters exponential smoothing model to forecast AMOUNT_SOLD on a quarterly basis for the next 4 quarters. It uses in-database modeling using ore.odmESM, and stores the trained model in the object MOD for further use.

    %r
     
    ore.drop(model = 'ESM_SALES_FORECAST_1')
     
    settings = list(EXSM_INTERVAL = 'EXSM_INTERVAL_QTR',
                    EXSM_PREDICTION_STEP = 4,
                    EXSM_MODEL = 'EXSM_HW',
                    EXSM_SEASONALITY = 4,
                    EXSM_ACCUMULATE = 'EXSM_ACCU_TOTAL',
                    MODEL_NAME='ESM_SALES_FORECAST_1',
                    case_id_column_name = "TIME_ID")
     
    MOD <- ore.odmESM(AMOUNT_SOLD~.,
                      SALES_TIME_AMOUNT,
                      odm.settings= settings)

    Examine the script:

    • EXSM_INTERVAL: Specifies the interval of the dataset or the unit of interval size, such as day, week, month, etc. This setting applies only to the time column of datetime type. For example, if you want to predict quarterly sales, set this to EXSM_INTERVAL_QTR.
    • EXSM_PREDICTION_STEP: Specifies how many future predictions to make. For example, if you want to predict one value per quarter, setting this to 4 will generate predictions for four quarters into the future.
    • EXSM_MODEL: Specifies the type of exponential smoothing model to be used. As an example, EXSM_WINTERS represents the Holt-Winters triple exponential smoothing model with additive trend and multiplicative seasonality. This type of model considers various combinations of additive and multiplicative trend, seasonality and error, with and without trend damping.
      • Additive trend: A trend where the increase or decrease in values happens by adding a constant amount over time.
      • Multiplicative trend: A trend where values grow or shrink by multiplying by a constant factor over time (e.g., percentage growth).
      • Seasonality: Refers to regular, repeating patterns or fluctuations in a time series that happen at specific intervals—like daily, weekly, monthly, or yearly.
      • Error components: The random noise or unexplained fluctuations in the data that aren’t captured by trend or seasonality.
      • Trend damping: A technique that slows down (reduces) the trend growth or decline over time, preventing it from continuing indefinitely at the same rate.
    • EXSM_SEASONALITY: This parameter specifies the length of the seasonal cycle and must be a positive integer greater than 1. For example, if the value is 4, it means the seasonal pattern repeats every 4 time periods—such as the four quarters in a year. In this case, each group of four consecutive values represents one complete seasonal cycle.
    • EXSM_SETMISSING: Specifies how to handle missing values. The special value EXSM_MISS_AUTO indicates that if the time series contains missing values, it should be treated as an irregular time series.

This completes the model building stage.