How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions?

How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions?

book

Article ID: KB0074224

calendar_today

Updated On:

Products Versions
Spotfire Statistica 13.0 and higher

Description

This article shows:

1. How to perform Neural Network Time Series Regression Analysis to make predictions

2. How to deploy C code (neural network models) generated from time series regression to make predictions

Issue/Introduction

How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions?

Environment

Windows

Resolution

1. How to perform Neural Network Time Series Regression Analysis to make predictions?

For illustration purpose, take a simple spreadsheet IrisdatTest.sta (attached in this article) as example to build the network models.

1. Open the example spreadsheet IrisdatTest.sta in Statistica, go to "Data Mining" | "Neural Networks" to open the Neural Network dialog. Select "Time series (regression)" under "New Analysis".

2. In the Neural Network analysis (SANN) dialog, Click on "Variables" to select V1 as Continuous target variable & V2,V3 as Continuous Input variables.

3. Click on "Time Series" tab, specify the "Number of time steps used as inputs" (e.g. 3), and the "Number of steps ahead to predict" (e.g. 5). Click OK.

4. In the SANN dialog, click on "Train" to build the network models. After execution, multiple network models will be produced and listed.

5. Click on "Select/Deselect Active networks" to select one network of interest. Click OK.

6. The selected network model will be listed. Under "Predictions" tab, select "Inputs, Targets, Output" to include in the prediction output table. Click on "Predictions".

7. The predictions will be listed together with input and target variables.

Notice that: Number of time steps used as inputs = 3; Number of steps ahead to predict =5

In the prediction output table,

  • Case 1,2,3 are used as inputs to make prediction of Case 8 (5 steps ahead)
  • Case 2,3,4 are used as inputs to make prediction of Case 9
  • Case 3,4,5 are used as inputs to make prediction of Case 10
  • Similarly for the rest of the cases in the dataset
  • Last 3 cases in the dataset (Case 18,19,20) are used as inputs to make prediction of Case 25

Therefore, before doing the time series analysis for prediction, users have to enter empty rows at the end of input dataset (5 empty rows in this example for IrisdatTest.sta) to allow the program make predictions.

 

2. How to deploy C code neural network models from Neural Network Time Series Regression Analysis to make multiple predictions?

1. After building and selecting the prediction model of interest, one can save the network model in C code for deployment.

An example of C code generated from above process is attached in this article (OriginalIrisdatTest.c)

2. Open the example C code in Notepad, notice that there is a main() function in this C code.

3. When compiling the original C code that Statistica generates, it will ask user to manually enter inputs from console window (keyboard).

The main() function Statistica provide in original C code is just a test bed program, so users can understand how to use the functions in the generated C code. For practical situations, users can take this code and use/modify the functions in it as required in their test environment.

For example, User can modify the main() function in the C code to read step inputs from an input file (e.g text file) instead of entering input values manually from keyboard. User can use a loop to make multiple predictions.

Below is an example of modified C code main() function, which takes input file from local drive (e.g. C:\\test.txt), read the text file for step inputs, and make multiple predictions using a For Loop. Example test.txt file is attached in this article.

4. Compile the example C code with above modified main() function, below is how the prediction looks like:

Attachments

How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions? get_app
How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions? get_app
How to perform Neural Network Time Series analysis & deploy C Code network models to make predictions? get_app