Search code examples
node.jsdeep-learningartificial-intelligencebrain.js

How do I fix the NaN training error in Brain.js?


I've got a problem with my neural net and I really need your help.

When the network is training, it gets me this output:

iterations: 10, training error: NaN

iterations: 20, training error: NaN

and so on...

I've tried so far:

  • to use for training only data with output 0 or 1
  • to normalize data
  • to flatten the input

Here is my training data.

Here is my code:

const Brain = require('brain.js'),
fs = require('fs'),
config = {
    logPeriod: 10,
    log: true,
    iterations: 100
};

let trainingData = JSON.parse(fs.readFileSync('./data/trainingData.normalized.json', 'utf8'));

const net = new Brain.NeuralNetwork({
    hiddenLayers: [72, 72]
});

net.train(trainingData, config);

console.log(net.run(trainingData[0].input));

Any help will be appreciated!


Solution

  • This answer has been edited.

    It looks like you're using nested arrays. 340 inputs where the input is 72 arrays of 72 arrays. I'm not sure how you flattened your inputs before, but using your training data and your code I was able to get a training error of 0.18139151128039302 by doing this:

    for (let datum of trainingData) {
         datum.input = datum.input.flat()
    }
    const train = net.train(trainingData, config);