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

strange regression coefficients #73

Open
vohtaski opened this issue Oct 12, 2017 · 7 comments
Open

strange regression coefficients #73

vohtaski opened this issue Oct 12, 2017 · 7 comments
Assignees

Comments

@vohtaski
Copy link

I am trying to fit the polynomial line into the data-set below as polynomial with order or 4 and 10,
and all coefficients are 0. Is it normal? Polynomial of high degree should normally over-fit the data,
but here it is just a line.

regression version: 2.0.0

// [[x,y]]
var data = [[0,90],[45,93],[90,92],[135,90],[180,89],[225,90],[270,88],[315,89],[360,85],[405,85],[450,90],[495,94],[540,87],[585,89],[630,91],[675,94],[720,88],[765,92],[810,76],[855,81],[900,83],[1215,94],[1260,91],[1305,85],[1350,83],[1395,85],[1440,82],[1485,81],[1530,83],[1575,82],[1620,84],[1665,84],[1710,87],[1755,87],[1800,89],[1845,86],[1890,83],[1935,88],[1980,78],[2025,78],[2070,66],[2115,59],[2250,87],[2295,94],[2430,87],[2475,88],[2520,88],[2565,87],[2700,90],[2745,93],[2790,91],[2835,86],[2880,89],[2925,88],[2970,90],[3015,89],[3060,90],[3105,88],[3150,85],[3195,91],[3240,91],[3285,85],[3330,87],[3375,87],[3420,89],[3465,93],[3510,87],[3555,90],[3600,92],[3645,91],[3690,90],[3735,88],[3780,78],[3825,90],[3870,93],[3915,91],[3960,91],[4005,90],[4050,89],[4095,94],[4140,88],[4185,89],[4230,82],[4275,77],[4320,79],[4365,103],[4635,111],[4680,88],[4725,74],[4770,81],[4815,87],[4860,80],[4905,87],[4950,80],[4995,85],[5040,87],[5085,89],[5130,91],[5175,87],[5220,90],[5265,90],[5535,82],[5580,73],[5625,87],[5670,94],[5715,95],[5760,100],[5805,100],[5850,98],[5895,101],[5940,107],[6030,95],[6075,92],[6120,94],[6165,88],[6210,86],[6255,85],[6300,89],[6345,96],[6390,94],[6435,87],[6480,89],[6525,89],[6570,93],[6615,86],[6660,90],[6705,85],[6750,88],[6795,85],[6840,86],[6885,89],[6930,85],[6975,91],[7020,84],[7065,91],[7290,89],[7560,94]];

regression.polynomial(data, {order: 4})
// "y = 0x^4 + 0x^3 + 0x^2 + -0.01x + 92.01"
regression.polynomial(data, {order: 10})
// "y = 0x^10 + 0x^9 + 0x^8 + 0x^7 + 0x^6 + 0x^5 + 0x^4 + 0x^3 + 0x^2 + -0.01x + 91.64"

Data looks like this:
screen shot 2017-10-12 at 10 34 12 am

@vohtaski
Copy link
Author

I just checked the version 1.4.0 and it's working on the data above:
regression('polynomial' data, 4)
screen shot 2017-10-12 at 12 37 58 pm

regression('polynomial' data, 10)
screen shot 2017-10-12 at 12 38 29 pm

@gtjamesa
Copy link

I have been issues with polynomial on 2.0.0 - thanks for posting that version 1.4.0 works :)

@Tom-Alexander
Copy link
Owner

Can I please have more information about the discrepancies between 2.0.0 and 1.4.0? The coefficients are the same between versions for me. This could be caused by rounding as 2.0.0 rounds by default. It can be configured with the precision option.

@Tom-Alexander Tom-Alexander self-assigned this Dec 10, 2017
@billy0059
Copy link

I had a similar issue in the "linear" method, but the problem was caused from the parameters passing.
The parameter array I passed is considered as a string array, so the addition operation sum[0] += data[n][0]; sum[1] += data[n][1]; would lead to a false result.
Simply modified to sum[0] += parseInt(data[n][0]); sum[1] += parseInt(data[n][1]); solved my problem.

@lucamattiazzi
Copy link

lucamattiazzi commented Apr 11, 2018

i'm having the same problem, I too solved it with 1.4.0, but the explanation from @billy0059 is not clear to me, why was the value casted as string?
(btw, a regression in the new version was inevitable 😄)

@Eugeny
Copy link

Eugeny commented Aug 29, 2018

Here's another example of 2.0.0 providing weird results:

Input: [[1000,100],[101000,1000],[201000,2000],[301000,2500],[401604,2700.3333],[502208,2800],[602208,2900],[702208,2950],[802208,3000],[902208,3500]]

Output: y = 0x^4 + 0x^3 + 0x^2 + 0.01x + 52.61

@cboden
Copy link

cboden commented Dec 5, 2018

Tom-Alexander was right. To get 2.0 matching with 1.4 I just had to update my precision:

regression.polynomial(data, {order: 4, precision: 20});

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

7 participants