我有一个简单的绘图,其中包含 数组 中的两个数据集,我正在尝试使用回归来计算通过这些点的最佳拟合线。
然而,我得到的线远离数据点的左侧和上方。
我如何才能使该行位于正确的位置,我的代码还有其他提示和建议吗?
from pylab import *
Is = array([-13.74,-13.86,-13.32,-18.41,-23.83])
gra = array([31.98,29.41,28.12,34.28,40.09])
plot(gra,Is,'kx')
(m,b) = polyfit(Is,gra,1)
print(b)
print(m)
z = polyval([m,b],Is)
plot(Is,z,'k--')
如果有人好奇,数据是硅晶体管在不同温度下的带隙。
请您参考如下方法:
您必须小心将哪些数组作为 x 坐标传递,哪些作为 y 坐标传递。假设您在位置 x 处有数据值 y。然后你必须评估多项式wrt。 x 也是。
from pylab import*
Is = array([-13.74,-13.86,-13.32,-18.41,-23.83])
gra = array([31.98,29.41,28.12,34.28,40.09])
# rename the variables for clarity
x = gra
y = Is
plot(x, y, 'kx')
(m,b) = polyfit(x, y, 1)
print(b)
print(m)
z = polyval([m,b], x)
plot(x, z, 'k--')
show()
