Forecasting Oil Production Rate (Univariate Time Series)
Tags: Time Series Forecasting, Long Short Term Memory, Python, Forecasting, Machine Learning

It is vital in a massive industry like oil and gas to forecast future production; this enables them to optimize and avoid any disastrous situation. Big companies realized that developing and implementing machine learning into the industry can save a lot of money and reduce the destructive environmental effects.

Aka vanilla RNN, the traditional Recurrent Neural Network (RNN), has been applied for modeling sequential data as an approach of the recursive neural network. The critical characteristic of RNN is the delay recursion, allowing it to describe the dynamic performance of systems. This delay makes the model not only related to the inputs but also the previous target point. The main difference between RNN and ANN is that the previous output (at t-1) is considered.

Long short-term memory (LSTM) is a variation of RNN models with acceptable performance for sequence data, for example, time series. LSTM models have been widely used in various industries such as health, education, environment, etc. In this article, an LSTM model was proposed to forecast the oil production rate of an oil and gas field. Tensorflow was used to implement the time-series forecasting model.

The data set has 1024 data points with no certain time-step. Dataset has two columns, including time (day) and Well Oil Production Rate (WOPR) measured on bbl.

Stationary is an important factor in time series that means the statistical properties are constant over time. It is important because most analytical tools and statistical tests rely on it.

To make it stationary, the differencing technique has been used (the other method that would be suggested is logarithm transformation). The below code illustrates two functions to make the dataset stationary, then feed the model, and finally reverse the function to visualization:

Normalization is another crucial act on all numerical and time-series data for machine learning algorithms, which suggests transforming the scale of the dataset to be suitable for the model. Here, MaxMinScaler has been used to transform the scale to [-1, +1]. And the second function is the reverse to back to the original scale.

The final act is to make the dataset suitable for the time series algorithm. Here, the window size is 1. This means each generated data is predicted on previous ‘window-size ’ data at time t. The function to make time-series usable is:

A function that has been written to convert the array of the dataset into a matrix:

To evaluate the model, two types of error are used the Root-Mean-Square-Percentage-Error and Mean-Absolute-Percentage-Error.

The LSTM model contains two lstm hidden layers, including 14 neurons, each with a dropout of 0.5 for both layers. A dense layer of three neurons with the activation function of relu function, finally reaching one neuron to forecast the target.

The model has compiled with the optimizer of ‘adam’ and the loss function of ‘mean_squared_error.’ The batch size is 1.

80% of the dataset is used to train the model and 20% to test.

After ten epochs, the result shows that the mentioned errors for the test data set would be suggested as below:

RMSE = 0.8685

MAPE = 0.55797

A comparison of train and test between original data and fitted data would be suggested to visualize in a plot:

The source code is available on this repository.