Time Series Analysis and Forecasting of Web Service Metrics
By: Vaibhav Sethi
Tags: Machine Learning, Web Services, Time Series Analysis, Sarima, Time Series Forecasting

Getting Started…

What is Time series?

Time series is a collection of data points collected at constant time intervals. Examples of time series data can vary from application metrics like request rates in RPM to system metrics like Idle CPU % taken at constant time intervals.

In order to solve prediction problem with machine learning techniques, the data needs to be converted to time series format. Time series data have a natural temporal ordering. Time series analysis can be applied to real-valued, continuous data, discrete numeric data, or discrete symbolic data.

For the illustration I’ve used Python. Numpy, Pandas, Matpoltlib modules would be used for transformation & analysis, and Statsmodel would be used for the predictive model.

Statistics of Request Rate data

Few data points of time series

Time series graph representing request rates (in RPM) for a web service taken at every minute of interval.

Preprocessing Data Look at the graph for Request Rate in RPM above, do you see any challenges with the data? In the graph above you can observe that there are too many data points and spikes to work with. How to handle this? * Resampling : All the data points were taken at a minute interval. Resampling the data to hourly or daily or weekly can help reduce the number of data points to work with. In this example we will use average daily resampled values. * Transformation : Transformation like logarithm, square root or cube root can be applied to handle the spikes in the graph. In this example we will perform log transformation for the time series.

Observe that large number of data points have reduced and the graph looks smoother as a result of daily resampling.

Observe the values on the y-axis as a result of log transformation

Time series Basic

Univariate Vs. Mutli-variate Timeseries

Univariate Time series data consists of only one variable. Univariate analysis is the simplest form of data analysis where the data being analysed contains only one variable. Since it’s a single variable it doesn’t deal with causes or relationships. An example of this univariate time series could be request rate metrics.

When time series consists of two variables it is called Bivariate time series. The analysis of this type of data deals with causes and relationships and the analysis is done to find out the relationship among the two variables. Example of this could be % CPU Usage of a web service which depends on the request rate. These variables are often plotted on X and Y axis on the graph for better understanding of data and one of these variables is independent while the other is dependent.

Multivariate time series consists of three or more variables. Example of multi-variate time series could be stock prices which would depend on multiple variables.

Components of Time series

In order to come up with a suitable model for forecasting time series, it is important to understand the components of the time series data. Time series data mainly consists of the following components:

Trend

Trend shows the general tendency of the data to increase or decrease during a long period of time. A trend is a smooth, general, long-term, average tendency. It is not always necessary that the increase or decrease is in the same direction throughout the given period of time. The request rate for web service may show some kind of tendencies of movement over a long period of time.

Trend shows the general tendency of the data to increase or decrease during a long period of time. A trend is a smooth, general, long-term, average tendency. It is not always necessary that the increase or decrease is in the same direction throughout the given period of time. The request rate for web service may show some kind of tendencies of movement over a long period of time. Seasonality

These are short term movements occurring in data due to seasonal factors. The short term is generally considered as a period in which changes occur in a time series. Eg. an e-commerce web service may receive more traffic in certain months.

These are short term movements occurring in data due to seasonal factors. The short term is generally considered as a period in which changes occur in a time series. Eg. an e-commerce web service may receive more traffic in certain months. Cycle

These are long term oscillations occurring in a time series.

These are long term oscillations occurring in a time series. Error

These are the random or irregular movements in a time series. These are sudden changes occurring in a time series which are unlikely to be repeated.

Additive Vs. Multiplicative Model Simple decomposition model could be:

Additive model : Y[t] = T[t] + S[t] + e[t]

Multiplicative model : Y[t] = T[t] * S[t] * e[t] Where, Y[t] is the predicted value at time ‘t’, T[t], S[t] and e[t] are the trend component, seasonal component and error at time ‘t’ respectively.

Additive Decomposition Model for time series

Multiplicative Decomposition Model for time series

Stationary Series

Time series is said to be stationary if it has constant statistical properties over time, ie. the following:

constant mean

constant variance

an auto covariance that does not depend on time.

Most of the time series models require the time series to be stationary.

How to Check Stationarity of a Time Series?

Here are some ways to check the stationarity of a time series:

Rolling Statistics

We can plot the moving average or moving variance to check variation with time. Eg. Rolling average of requests per minute graph over period of 7 days. This is a visual technique.

We can to check variation with time. Eg. Rolling average of requests per minute graph over period of 7 days. This is a visual technique. Dickey-Fuller Test

This is one of the statistical tests for checking stationarity. It is a type of unit root test. The test results comprise of a Test Statistic and some Critical Values for difference confidence levels. If the ‘Test Statistic’ is less than the ‘Critical Value’, we can reject the null hypothesis and say that the series is stationary. Here the null hypothesis is that the time series is non-stationary.

Rolling Stats Plot and AD Fuller Test results for original time series

How to make a Time series Stationary?

There are multiple ways of making a time series stationary. Some of them are differencing, detrending, transformation, etc.