How do I create a best-fit polynomial curve in Javascript?
问题 I'm trying to calculate a best-fit curve for data using a 3-6 order polynomial. I found this tutorial: Cubic Regression (best fit line) in JavaScript First, I can't seem to get my outputs to remotely match the curve. jsbin here: http://jsbin.com/qukuqigobu/1/edit?html,js,console,output var data_x = [500,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000]; var data_y = [50,80,100,160,210,265,340,390,440,470,500,500,495,460]; var cubic = function(params,x) { return params[0] * x*x