本文介绍了brain.js-预测接下来的10个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在brain.js页面上,有一个LSTMTimeStep的简单示例- https://github.com /BrainJS/brain.js

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]

这足以预测下一个值/标签.但是,如果我有成千上万的训练集和成千上万的测试数据集,并且我想预测下一个10或100个值,该怎么办?该怎么做?

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?

推荐答案

我认为您需要使用Forecast方法才能预测一组值.

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

使用参数计数.

此处中查看预测部分.

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 ] ]

这篇关于brain.js-预测接下来的10个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 09:34