Nikicatz
Nikicatz

Reputation: 105

brain.js - predicting next 10 values

On the brain.js page there is a simple example of LSTMTimeStep - https://github.com/BrainJS/brain.js

var net = new brain.recurrent.LSTMTimeStep();
net.train([
  [1, 3],
  [2, 2],
  [3, 1],
]);    
var output = net.run([[1, 3], [2, 2]]);  // [3, 1]

This is good enough to predict the next value/label. But what if I have thousands of training set and thousands of test data set and I would like to predict next 10 or 100 values. How to do this?

Upvotes: 2

Views: 5387

Answers (2)

imamalis
imamalis

Reputation: 65

I think that you need to use the forecast method in order to predict a set of values .

Use the parameter count.

Check the prediction section here.

I did an example and seems to work

const net = new brain.recurrent.LSTMTimeStep({
    inputSize: 3,
    hiddenLayers: [10],
    outputSize: 3
});

//Same test as previous, but combined on a single set
const trainingData = [
    [8,8,1],[8,8,3],[8,8,5],[8,2,8],[3,6,6],[8,4,5]
];

net.train(trainingData, { log: true, iterations:200 });

console.log( net.run([[8,2,3]]));

console.log( net.forecast([[8,8,2]], 7)) ;

below you can see the results:

iterations: 0, training error: 14.974015071677664
iterations: 10, training error: 4.263545592625936
iterations: 20, training error: 4.1400322914123535
iterations: 30, training error: 4.106281439463298
iterations: 40, training error: 4.019651651382446
iterations: 50, training error: 3.9397279421488443
iterations: 60, training error: 3.7364938259124756
iterations: 70, training error: 3.594826857248942
iterations: 80, training error: 3.4333037535349527
iterations: 90, training error: 3.2692082722981772
iterations: 100, training error: 3.0003069241841636
iterations: 110, training error: 2.741880734761556
iterations: 120, training error: 2.559309403101603
iterations: 130, training error: 2.549466371536255
iterations: 140, training error: 2.165259758631388
iterations: 150, training error: 1.912764310836792
iterations: 160, training error: 1.7081804275512695
iterations: 170, training error: 1.5422560373942058
iterations: 180, training error: 1.3950440088907878
iterations: 190, training error: 1.2614964246749878
Float32Array [ 7.450448036193848, 7.630088806152344, 3.102810859680176 ]
[ Float32Array [ 7.769495010375977, 7.626269340515137, 3.01503324508667 ],
  Float32Array [ 8.504044532775879, 7.038702011108398, 5.765346050262451 ],
  Float32Array [ 7.573630332946777, 3.117426872253418, 8.106966018676758 ],
  Float32Array [ 4.165530204772949, 5.516692161560059, 5.85803747177124 ],
  Float32Array [ 6.954248428344727, 3.7581958770751953, 5.24238920211792 ],
  Float32Array [ 5.5002217292785645, 4.540862560272217, 6.505147457122803 ],
  Float32Array [ 6.376245498657227, 4.115119934082031, 5.876959323883057 ] ]

Upvotes: 4

Farrukh Subhani
Farrukh Subhani

Reputation: 2038

You need to train with given sets and then if you want you can do following for next 10 items: Predict next item. Add it to training set. Predict next +1 item. Add next +1 to training set.

Also read about the stream on github repo. I also suggest you update your question with what you have tried so far it will help future users to understand the question further and add to both question and answer.

Upvotes: 0

Related Questions