在日常数据分析中,免不了要用到数据曲线拟合,而optimize.curve_fit()函数正好满足你的需求
scipy.optimize.curve_fit(f,xdata,ydata,p0=None,sigma=None,absolute_sigma=False,check_finite=True,bounds=(-inf,inf),method=None,jac=None,**kwargs)
参数解析f 函数名
callable
The model function, f(x, …). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.
简单来说就是需要拟合的好函数y,包括自变量x,参数A,B;
而curve_fit的主要功能就是计算A,B
#要拟合的一次函数
def f_1(x, A, B):
return A * x + Bxdata
array_like or objectThe independent variable where the data is measured. Should usually be an M-length sequence or an (k,M)-shaped array for functions with k predictors, but can actually be any object.
ydata
array_likeThe dependent data, a length M array - nominallyf(xdata,...).
p0
array_like , option