3

I have to use Excel's LINEST function to compute error in my linear regression. I was hoping to reproduce the results using Numpy's polyfit function. I was hoping to reproduce the following LINEST usage:

LINEST(y's, x's,,TRUE)

with polyfit. I'm not sure how I can get the two functions to produce the same values because nothing I've tried gives similar results.

I tried the following:

numpy.polyfit(x,y,3)

and various other values in the third position.

tlnagy
  • 3,274
  • 4
  • 24
  • 37
  • Please show your code. – abudis Feb 12 '14 at 09:39
  • possible duplicate of [6th degree curve fitting with numpy/scipy](http://stackoverflow.com/questions/10143174/6th-degree-curve-fitting-with-numpy-scipy) – abudis Feb 12 '14 at 09:42
  • I've read that SO question. I would like to reproduce the default LINEST function, not a specific degree polynomial. I edited the post to include the code that I tried. – tlnagy Feb 12 '14 at 15:30

1 Answers1

5

This question is actually a result of my misunderstanding of NumPy's polyfit function and LINEST. Doing the following:

 numpy.polyfit(x,y,1)

gave me the correct result because it performs a linear regression using the sample x and y values like LINEST.

tlnagy
  • 3,274
  • 4
  • 24
  • 37
  • Makes sense now. LINEST, for n columns, looks like y = m1*x1 + m2*x2 + ... + mn*xn. Which are all linear in the x's, hence the degree 1 fit. – Chris May 23 '16 at 15:54