python - how to use numpy polyfit to force scatter points linear fit pass through zero? -
x=np.asarray([1,2,4,5,7,8,9]) y=np.asarray([2,1,3,6,4,7,9]) m,b=np.polyfit(x,y,1)
i have scatter points , try linear fit (y = m*x + b, b = 0) numpy polyfit
. there way force interception b 0? can have variance?
i googled , said np.linalg.lstsq
may work don't know how manipulate it. , prefer np.polyfit
. can work?
no. np.polyfit
doesn't have method removing lower order terms. here's how np.linlg.lstsq
:
m = np.linalg.lstsq(x.reshape(-1,1), y)[0][0] m 0.87916666666666654
this not same as:
np.mean(y/x) 0.98520408163265305
Comments
Post a Comment