Linear regression to predict the y-value for the trend series
I have [x,y] pairs where x value is in Unix- time values and y in float. I am needing to find the best fit line for this series. I am using t开发者_如何转开发he linear regression model as in this link below:
http://dracoblue.net/dev/linear-least-squares-in-javascript/159/
I am getting the values correctly. But, Since my x-data is in unix timestamp, I get really huge values. So, has any one got any suggestions on how to tone it down? I tried using seconds instead of milliseconds, by diving the x-data by 1000. But, that just makes the difference in the final y-values very negligible and I don't see a proper trendline.
Any help would be appreciated.
Thanks,S.
Make it start at 0 : substract each occurence of a x value by what was the first x (say x0) value.
For instance, line 31 of your link :
replace x = values_x[v];
with x = values_x[v] - values_x[0];
If values_x is ordered and ascending then it should be ok
Can you subtract the first x value to the entire series so that the x start from 0?
精彩评论