I want to fit data to a Logistic (Sigmoid) function and am getting infinite covariance. I have 2 parameters and suppose I have 5 data points. My data are in the variables xdata
and ydata
. Here is a code example which generates the exact same warning:
from scipy.optimize import curve_fit
def sigmoid(x, x0, k):
y = 1 / (1 + np.exp(-k*(x-x0)))
return y
xdata = np.array([ 5., 75., 88., 95., 96.])
ydata = np.array([ 0.04761905, 0.02380952, 0, 0.04761905, 0])
popt, pcov = curve_fit(sigmoid, xdata, ydata)
which gives pcov
to be
array([[ inf, inf],
[ inf, inf]])
and the following warning:
OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning)
I saw a related question that led to the same problem here, but there the problem was that the number of data points and parameters was the same, which is not true in my case.
EDIT: Notice that above I have mentioned I have data points, but this is just for the example. In reality there are 60. Here is a plot of the raw data, to see that indeed a sigmoid function seems suitable: