I am trying to fit a logistic function to the data below. I am not able to understand why I get a straight line with fitted parameters? Can someone please help me with this?
x = [473,523,573,623,673]
y = [104,103,95,79,83]
x = np.array(x)
y = np.array(y)
def f(x,a,b,c,d):
return a/(1 np.exp(-c*(x-d))) b
popt, pcov = opt.curve_fit(f,x,y,method="trf")
y_fit = f(x,*popt)
plt.plot(x,y,'o')
plt.plot(x,y_fit,'-')
plt.show()
CodePudding user response:
A good choice of initial values can make the difference between a successful optimization and one that fails. For this particular problem I would suggest the initial values that you can find in the code below (p0
list). These values allows to properly estimate the covariance.
Moreover, you don't need to use the trf
algorithm since you are not providing any bound (see
If possible I would also suggest to increase the number of observations.