question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Throws a NaN even though dataset / output are just numbers.

See original GitHub issue

A GIF or MEME to give some spice of the internet

What is wrong?

Getting {"error": null, "iterations": 20000} even though training dataset are just numbers.

Where does it happen?

When brain.js trains data in my sample website running in Chrome 65 on Mac

How do we replicate the issue?

Input data: https://gist.github.com/digi0ps/65bebf027876f85b42ab7b4dd2ba49bf Code:

 let net = new brain.NeuralNetwork();
 net.train(encoded);
 trained  = net.toFunction()

How important is this (1-5)?

  1. Just trying to learn. But I’m curious as to why it’s not working

Expected behavior (i.e. solution)

Error shouldn’t have been NaN. When I run net.run with an input I get {english: NaN, tanglish: NaN} instead of values inside them.

Other Comments

Here is the NeuralNetwork object: https://gist.github.com/digi0ps/53292e8c55c31b7de8de9dcb06ea22e5

Can you help? Regards, Sriram.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
robertleeplummerjrcommented, Mar 19, 2018
2reactions
robertleeplummerjrcommented, Mar 19, 2018

The issue is that your input array lengths are staggered. A simple fix of the following will bring results:

const net = new brain.NeuralNetwork();
net.train(fixLengths(data));

function fixLengths(data) {
  let maxLengthInput = -1;
  for (let i = 0; i < data.length; i++) {
    if (data[i].input.length > maxLengthInput) {
      maxLengthInput = data[i].input.length;
    }
  }
  
  for (let i = 0; i < data.length; i++) {
    while (data[i].input.length < maxLengthInput) {
      data[i].input.push(0);
    }
  }
  
  return data;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

NaN - JavaScript - MDN Web Docs
The global NaN property is a value representing Not-A-Number. ... Even when this is not the case, avoid overriding it.
Read more >
Trying to add ints from database to a let but always ...
I've been trying to get some numbers from a table in my database (MySQL/PHPMyAdmin) and add those to a "let" in the code,...
Read more >
Handling Missing Data in Pandas: NaN Values Explained
NaN means missing data​​ Note also that np. nan is not even to np. nan as np. nan basically means undefined.
Read more >
If it's not a number, what is it? Demystifying NaN for the ...
Short for “Not a Number”, even its name is a paradox. Only floating-point values can be NaN, meaning that from a type-system point...
Read more >
Input contains NaN, infinity or a value too large for dtype ...
How do I find the bad values in the test dataset? Also, I do not want to drop these records, can I just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found