def model0(x, p1, p2):
    return p1 * np.cos(p2 * x) + p2 * np.sin(p1 * x)

def model1(x, p1, p2, p3):
    return p1 * np.cos(p2 * x) + p2 * np.sin(p1 * x) + p3 * x
p1, p2, p3 = 1, 0.2, 0.01
fit0 = so.curve_fit(model0, xdata, ydata, p0=(p1, p2))[0]
fit1 = so.curve_fit(model1, xdata, ydata, p0=(p1, p2, p3))[0]
yfit0 = model0(xdata, fit0[0], fit0[1])
yfit1 = model1(xdata, fit1[0], fit1[1], fit1[2])
ssq0 = ((yfit0 - ydata) ** 2).sum()
How to calculate the likelihood of curve-fitting in scipy?