Introduction of neural-redis, part 2

The machine learning module for redis

Series

Introduction of neural-redis, part 1

Train the neural network

NR.OBSERVE is used to insert training examples for supervised learning. A training example should include the input(s) and the expected output(s).

If we want the neural network to infer the function as below:

Recap the definition in part 1:

Thus the neural network will actually infer the tunable parameters, to get the following equation:

Here is one of the examples:

> NR.OBSERVE net 1 2 -> 3
1) (integer) 1
2) (integer) 0

The inserted dataset 1 2 -> 3 will be appended into either training dataset or testing dataset.

You can specify the inserted training example to be appended in training dataset or testing dataset. If not specified, it will be appended based on fill percentage, which is set in NR.CREATE (introduced in part 1) previously.

The first returned value is the number of updated training dataset; the second returned value is the number of updated testing dataset.

Assuming we have several training examples inserted as below:

> NR.OBSERVE net 4 5 -> 9
> NR.OBSERVE net 3 4 -> 7
> NR.OBSERVE net 1 1 -> 2
> NR.OBSERVE net 2 2 -> 4
> NR.OBSERVE net 0 9 -> 9
> NR.OBSERVE net 7 5 -> 12
> NR.OBSERVE net 3 1 -> 4
> NR.OBSERVE net 5 6 -> 11

We can train the neural network via NR.TRAIN :

> NR.TRAIN net AUTOSTOP

AUTOSTOP is given for the auto detection of overfitting, which is based on the error rate in training/testing data.

neural-redis uses RPROP algorithm to train the neural network. The actual implementation is referred to this paper.

Run the neural network

Let’s see how it predicts the output via NR.RUN:

> NR.RUN net 1 1
1) "2.0776522297040843"

> NR.RUN net 3 2
1) "5.1765427204933099"

The accuracy of the prediction is related to the variety of training examples, the number of inserted training examples, and the number of dataset we’ve trained.

Here is how we get the details of the training in the neural network:

> NR.INFO net
1) id
2) (integer) 1
3) type
4) regressor
5) auto-normalization
6) (integer) 1
7) training
8) (integer) 0
9) layout
10) 1) (integer) 2
2) (integer) 3
3) (integer) 1
11) training-dataset-maxlen
12) (integer) 50
13) training-dataset-len
14) (integer) 6
15) test-dataset-maxlen
16) (integer) 10
17) test-dataset-len
18) (integer) 2
19) training-total-steps
20) (integer) 1344
21) training-total-seconds
22) 0.00
23) dataset-error
24) "7.5369825612397299e-05"
25) test-error
26) "0.00042670663615723583"
27) classification-errors-perc
28) 0.00

There are 6 examples in training dataset and 2 examples in testing dataset. Also the neural network was trained with 1344 steps in just a few milliseconds.

What is next?

Part 3 will show you how to do the classification.

Reference

http://deeplearning.cs.cmu.edu/pdfs/Rprop.pdf

Other languages

中文: neural-redis簡介,第二部分