我有两个NumPy数组x和y。当我尝试使用指数函数和curve_fit(SciPy)来拟合我的数据时,使用以下简单代码:
我得到了错误的系数
什么是问题?
#!/usr/bin/env python
from pylab import *
from scipy.optimize import curve_fit
x = np.array([399.75, 989.25, 1578.75, 2168.25, 2757.75, 3347.25, 3936.75, 4526.25, 5115.75, 5705.25])
y = np.array([109,62,39,13,10,4,2,0,1,2])
def func(x, a, b, c, d):
return a*np.exp(b-c*x)+d
popt, pcov = curve_fit(func, x, y)
我得到了错误的系数
popt
。[a,b,c,d] = [1., 1., 1., 24.19999988]
什么是问题?