Reproducing Excel's LINEST function with NumPy

≯℡__Kan透↙ 提交于 2021-02-08 04:45:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!