问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/21720523/reproducing-excels-linest-function-with-numpy