Time Series Forecasting with Deep Learning

In this article, we will make a sample application with LSTM (Long-Short Term Memory), a special type of RNN (Recurrent Neural Network) that can make more successful forecasting than statistical methods in time series forecasting according to the studies in the literature.

RNN and LSTM architecture

In the work to be done, we will forecas tthe CPU usage that will occur in the following hours (out-of-sample) on the data that is the hourly average of the server CPU usage rate.

Head of Data

As a requirement, each value of the time series must be of the float data type in order to establish the LSTM model on the data.

To obtain the input(X) and output(y) required to train the model, we give the following function the CPU usage values in array format.

With the n_steps_in and n_steps_out parameters, we specify how many values will be given as input to the model and the output we want to receive, ie how many hours we want to estimate. The n_features parameter indicates the number of features to be predicted.

We determine the function parameters and implement the function.
Then X and y:

Now we’re ready to create the LSTM model.

For nonlinear relationships modeling, we give the activation function to the model as the ‘relu’ function that assigns zero to values below zero and its own value to values above zero, and the Epoch value, which expresses how many times all values will pass through the model.

Model Fitting

After training our model as above, we provide the CPU usage in the last 24 hours as input to the model and forecast the next 3 hours to be array as below.

Prediction Phase

Thus, we estimate the server CPU usage that will occur in the next 3 hours as an out-of-sample.

Forecasting Result
  • Additionally,
  • to see the accuracy of the model

model.compile(optimizer=’adam’, loss=’mse’, metrics = ‘accuracy’)

  • to optimize the model you may use MinMaxNormalization:

scaler = MinMaxScaler()

normData = scaler.fit_transform(dataset.values)

Thanks for reading, stay with data :)

Research Assistant at Yeditepe University, MSc