|
28 | 28 | + [For training with `RNN`, `LSTM` and `GRU`](#for-training-with-rnn-lstm-and-gru)
|
29 | 29 | + [Training Options](#training-options)
|
30 | 30 | + [Async Training](#async-training)
|
| 31 | + + [Cross Validation](#cross-validation) |
| 32 | + + [Train Stream](#train-stream) |
31 | 33 | - [Methods](#methods)
|
32 | 34 | + [train](#train)
|
33 | 35 | - [Failing](#failing)
|
@@ -274,6 +276,49 @@ With multiple networks you can train in parallel like this:
|
274 | 276 | .catch(handleError);
|
275 | 277 | ```
|
276 | 278 |
|
| 279 | +### Cross Validation |
| 280 | +[Cross Validation](https://en.wikipedia.org/wiki/Cross-validation_(statistics)) can provide a less fragile way of training on larger data sets. The brain.js api provides Cross Validation in this example: |
| 281 | +```js |
| 282 | +const crossValidate = new CrossValidate(brain.NeuralNetwork); |
| 283 | +const stats = crossValidate.train(data, networkOptions, trainingOptions, k); //note k (or KFolds) is optional |
| 284 | +const net = crossValidate.toNetwork(); |
| 285 | + |
| 286 | + |
| 287 | +// optionally later |
| 288 | +const json = crossValidate.toJSON(); |
| 289 | +const net = crossValidate.fromJSON(json); |
| 290 | +``` |
| 291 | + |
| 292 | +An example of using cross validate can be found in [examples/cross-validate.js](examples/cross-validate.js) |
| 293 | + |
| 294 | +### Train Stream |
| 295 | +Streams are a very powerful tool in node for massive data spread across processes and are provided via the brain.js api in the following way: |
| 296 | +```js |
| 297 | +const net = new brain.NeuralNetwork(); |
| 298 | +const trainStream = new brain.TrainStream({ |
| 299 | + neuralNetwork: net, |
| 300 | + floodCallback: function() { |
| 301 | + flood(trainStream, data); |
| 302 | + }, |
| 303 | + doneTrainingCallback: function(stats) { |
| 304 | + // network is done training! What next? |
| 305 | + } |
| 306 | +}); |
| 307 | + |
| 308 | +// kick it off |
| 309 | +readInputs(trainStream, data); |
| 310 | + |
| 311 | +function readInputs(stream, data) { |
| 312 | + for (let i = 0; i < data.length; i++) { |
| 313 | + stream.write(data[i]); |
| 314 | + } |
| 315 | + // let it know we've reached the end of the inputs |
| 316 | + stream.endInputs(); |
| 317 | +} |
| 318 | +``` |
| 319 | + |
| 320 | +An example of using train stream can be found in [examples/stream-example.js](examples/stream-example.js) |
| 321 | + |
277 | 322 | # Methods
|
278 | 323 | ### train
|
279 | 324 | The output of `train()` is a hash of information about how the training went:
|
@@ -341,7 +386,7 @@ The network now has a [WriteStream](http://nodejs.org/api/stream.html#stream_cla
|
341 | 386 |
|
342 | 387 |
|
343 | 388 | ### Example
|
344 |
| -Refer to [`stream-example.js`](./examples/cli/stream-example.js) for an example on how to train the network with a stream. |
| 389 | +Refer to [`stream-example.js`](examples/stream-example.js) for an example on how to train the network with a stream. |
345 | 390 |
|
346 | 391 |
|
347 | 392 | ### Initialization
|
|
0 commit comments