D3.js linear regression

前端 未结 2 832
失恋的感觉
失恋的感觉 2020-12-29 13:35

I searched for some help on building linear regression and found some examples here:
nonlinear regression function
and also some js libraries that should cover this

2条回答
  •  自闭症患者
    2020-12-29 14:16

    It looks to me like your path is getting drawn, just way off the screen.

    path element in firebug

    Perhaps the regression is calculated incorrectly? The problem may be on line 202:

    var data = [x.domain(), y.domain()];
    var result = regression('linear', data);
    

    If the raw data looks like [[1, 500], [2, 300]] this will find the linear regression of [[1, 2], [300, 500] which probably isn't what you want.

    I'm guessing what you'd like to do is compute the regression with the entire set of data points rather than with the graph's bounds. Then rather than charting this line for every data value, you want to just plot the endpoints.

提交回复
热议问题