# LSTM for Time Series Prediction — Part I

**Time Series Predictions**

A time series contains a sequence of data points observed at specific intervals over time. A time series prediction uses a model to predict future values based on previously observed values. The natural temporal order of time series data makes analysis of time series different from cross-sectional or spatial data analyses, neither of which depends on a time component.

Time series predictions can be useful in a variety of settings, from processing signal data streaming from a sensor at an industrial site to monitoring trends in a financial market or maintaining inventory in a commercial setting. In all these scenarios, recent data can be used to inform predictions about future goal values.

**Difference between non-time series and time-series data**

Non-time series data can originate from many subjects and contains values that either do not vary over time or are measured at only a single point in time. Non–time series data can include data about many features, is not order-dependent, and is ready for analytics as is. Examples:

- With knowledge of gross revenue and recent stock prices, predict next week’s stock price.

- With knowledge of average global temperature over the last 100 years, predict the average temperature 20 years from now.

Time series data also differs somewhat from non-time series data in the training of predictive models. A look-back window parameter is required for training time series models. The look-back window defines the number of recent data points to be used when predicting each future value in the time series. Any value greater than 1 is acceptable but generally, a power of 2 is used. Larger values affect performance because more records are used for predictions.

**Why LSTMs are preferred?**

There are several time-series forecasting techniques like autoregression (AR) models, moving average (MA) models, Holt-winters, ARIMA etc., to name a few. So, what is the need for yet another model like LSTM-RNN to forecast time-series? This is quite a valid question, to begin with:

· LSTMs are pretty good at extracting patterns in input feature space, where the input data spans over long sequences. Given the gated architecture of LSTM’s that has this ability to manipulate its memory state, they are ideal for such problems.

· LSTMs can almost seamlessly model problems with multiple input variables. All we need is a 3D input vector that needs to be fed into the input shape of the LSTM. So long as we figure out a way to convert all our input variables to be represented in a 3D vector form, we are good to use LSTM. This adds a great benefit in time series forecasting, where classical linear methods can be difficult to adapt to multivariate or multiple input forecasting problems (A side note here for multivariate forecasting — keep in mind that when we use multivariate data for forecasting, then we also need “future multi-variate” data to predict the future outcome!)

· LSTMs offer a lot of flexibility in modeling the problem — meaning we have good control over several parameters of the time series.

In the next article, using synthetically generated data, we show LSTMs have an upper hand in predicting time-series data compared to other approaches.

Masala.AI

The Mindboard Data Science Team explores cutting-edge technologies in innovative ways to provide original solutions, including the Masala.AI product line. Masala provides media content rating services such as vRate, a browser extension that detects and blocks mature content with custom sensitivity settings. The vRate browser extension is available for download via the Chrome Web Store. Check out www.masala.ai for more info.