Dhr*_*tel 0 python numpy matplotlib scipy pandas
我想知道如何执行线性逼近并从python中的数据数组中获取线性方程.
即它会是这样的
linapprox((0,0),(1,1),(2,1.9),(3,3.1))
> y = x
Run Code Online (Sandbox Code Playgroud)
polyfit 会工作
x=np.arange(0,4)
y=np.array([0,1,1.9,3.1])
np.polyfit(x,y,1)
Run Code Online (Sandbox Code Playgroud)
给
array([ 1.02, -0.03])
Run Code Online (Sandbox Code Playgroud)
这两个值是m和c,其中y = mx + c
你可以围绕这个:
np.round(np.polyfit(x,y,1))
Run Code Online (Sandbox Code Playgroud)
给你想要的东西:
array([ 1., 0.])
Run Code Online (Sandbox Code Playgroud)