Predict inflation using machine learning

Inflation is the rate of increase in the cost of goods and services over a given period of time. This example aims to predict inflation from the macroeconomic data of a country.

Contents:

  1. Application type.
  2. Data set.
  3. Neural network.
  4. Training strategy.
  5. Model selection.
  6. Testing analysis.
  7. Model deployment.

This example is solved with Neural Designer. In order to follow this example step by step, you can use the free trial.

1. Application type

This is a forecasting project, since the variable to predict is the future inflation.

The goal here is to model the inflation rate for the next month from different macroeconomic features of the past three months.

2. Data set

The data set contains information to create our model. We need to configure three things:

The data file used for this example is macroeconomics.csv, which contains monthly information about 16 features for 19 years.

The data set includes the following variables:

On the other hand, the instances are divided sequentially into training, selection and testing subsets, containing 60%, 20% and 20% of the instances, respectively.

We can calculate the inputs-target correlations. These indicate which macroeconomic factors have the most significant influence on inflation.

In this example, there are a few variables that correlate highly with the target variable. They are WIBOR_3M, consumer_price_index, and reference_rate_NBP.

We can also check the time series charts for these variables.

Looking at the time series plot for the target variable, we can see that core inflation has been in the same range for the past 15 years.

We can also look at the WIBOR_3M chart. If we compare the two previous plots, we see the correlation between the two variables.

3. Neural network

The next step is to set the neural network parameters. In our case, it is composed of:

We could have also used a LSTM layer.

For the scaling layer, the mean and standard deviation scaling method has been set.

Next, we set one perceptron layer with 3 neurons that have the hyperbolic tangent activation function. This layer has 45 inputs, which are the 15 variables of the dataset for three months. The output is one, the core_inflation for the next month.

The neural network for this example can be represented with the following diagram:

4. Training strategy

The fourth step is to set the training strategy, which defines what the neural network will learn. A general training strategy for classification is composed of two terms:

The loss index chosen for this problem is the normalized squared error between the outputs from the neural network and the targets in the data set with L1 regularization.

The selected optimization algorithm is the Quasi-Newton method.

The following chart shows how the training error develops with the epochs during the training process. The final value is training error = 0.00641 NSE and selection error = 0.289 NSE.

5. Model selection

The objective of model selection is to improve the neural network's generalization capabilities or, in other words, to reduce the selection error.

First, we perform the neurons selection. We want a model whose complexity is the most appropriate to produce an adequate fit of the data. The optimal value for this example is one neuron.

Next, we will apply an input selection algorithm. This reduces our inputs to six: the consumer_price_index and the core_inflation for the past three months.

The resulting neural network is as follows.

With it, the selection error decreases to selection error = 0.0578 NSE. It is a great improvement compared to the previous value.

6. Testing analysis

The objective of the testing analysis is to validate the generalization performance of the trained neural network. To validate a forecasting technique, we need to compare the values provided by this technique to the observed values. We can use the linear regression analysis as it is the standard testing method for these projects.

The correlation value for this example is R2 = 0.977, which is close to 1. This means that we have a good predictive model.

We can also calculate the error statistics. The mean absolute error obtained by using the previous value as the prediction is 0.320. Using the model, it lowers to 0.186. Therefore, we are improving the prediction of the core inflation.

The final testing method we will use is the outputs plot. This will plot the real values (blue) and the predicted values (orange) over time.

7. Model deployment

The next listing shows the mathematical expression of the predictive model.

            scaled_consumer_price_index_lag_2 = (consumer_price_index_lag_2-2.143300056)/1.813670039;
            scaled_core_inflation_lag_2 = (core_inflation_lag_2-1.542860031)/1.364359975;
            scaled_consumer_price_index_lag_1 = (consumer_price_index_lag_1-2.121880054)/1.779330015;
            scaled_core_inflation_lag_1 = (core_inflation_lag_1-1.52410996)/1.32277;
            scaled_consumer_price_index_lag_0 = (consumer_price_index_lag_0-2.10345006)/1.753630042;
            scaled_core_inflation_lag_0 = (core_inflation_lag_0-1.507590055)/1.288020015;

            perceptron_layer_1_output_00 = tanh( -0.42611 + (scaled_consumer_price_index_lag_2*-0.0133176) + (scaled_core_inflation_lag_2*-0.0242241) + (scaled_consumer_price_index_lag_1*-0.0445507) + (scaled_core_inflation_lag_1*0.0669062) + (scaled_consumer_price_index_lag_0*0.119317) + (scaled_core_inflation_lag_0*0.287741) );

            perceptron_layer_2_output_00 = ( 1.14009 + (perceptron_layer_1_output_0*3.096) );

            unscaling_layer_output_0 = -0.400000006+0.5*(perceptron_layer_2_output_0+1)*(6.5+0.400000006);

            core_inflation_ahead_1 = max(-0.400000006, unscaling_layer_output_0)
            core_inflation_ahead_1 = min(6.5, unscaling_layer_output_0)

This formula can also be exported to the software tool required by the company.

References

Related examples:

Related solutions: