Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polynomial regression with specify options return NaN #95

Open
throrin19 opened this issue Jul 23, 2019 · 2 comments
Open

polynomial regression with specify options return NaN #95

throrin19 opened this issue Jul 23, 2019 · 2 comments

Comments

@throrin19
Copy link

Hi, I've a problem with the polynomial regression if I set the option (empty or not) :

var series 	= [[0, 10], [1 ,3], [2, 0], [3, 2], [4, 4], [5, 0], [6, 0], [7, 0], [8, 1], [9, 3]];

// works fine
var result = regression('polynomial', series);

// does not works
var result = regression('polynomial', series, {});
var result = regression('polynomial', series, { order : 2 });
var result = regression('polynomial', series, { order : 3 });
// ...

For information, I use that with the CDN version of regression (version 1.4.0 : https://cdnjs.cloudflare.com/ajax/libs/regression/1.4.0/regression.min.js)

And this is the result if this does not works :

{
  "r2": null,
  "equation": [
    "[object Object]1"
  ],
  "points": [
    [
      0,
      null
    ],
    [
      1,
      null
    ],
    [
      2,
      null
    ],
    [
      3,
      null
    ],
    [
      4,
      null
    ],
    [
      5,
      null
    ],
    [
      6,
      null
    ],
    [
      7,
      null
    ],
    [
      8,
      null
    ],
    [
      9,
      null
    ]
  ],
  "string": "y = NaN"
}
@ruidiasbraga
Copy link

I am also having the same problem? any solution?
This is related with the Math.log(); with zero values, return "-infinity" and translates to "NaN" but I don't want to make a custom code for this, I prefer to wait and update the file from github.

@timoklingenhoefer
Copy link

the error occurs here:

const coefficients = gaussianElimination(rhs, k).map((v) => round(v, options.precision));

the polynomial regression needs the precision option. Otherwise the round function tries to devide by null.
So you have to change

var result = regression('polynomial', series, { order : 2 });

to

var result = regression('polynomial', series, { order : 2, precision: 3 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants