0

I am hoping someone can me with where I'm going wrong with fitting a curve to this data. I am using the method in this link and so have the following code:

def sigmoid(x, L, x0, k, b):
    y = L / (1 + np.exp(-k*(x-x0)))+b
    return y

p0 = [max(y1), np.median(x2), 1, min(y1)]

popt, pcov = curve_fit(sigmoid, xdata=x2, ydata=y1, p0=p0, method='dogbox')

predictions = sigmoid(x2, *popt)

And my plotted "curve" looks like so:

screenshot

But I am expecting a more s-shaped curve. I have experimented with different p0 values but not getting the required output (and if I'm honest I'm not sure how I'm supposed to find the ideal starting parameters).

Using p0 = [max(y1), np.median(x2), 0.4, 1] and method='trf I did get the following, which is closer but still missing the curve in the middle?

enter image description here

Any help greatly appreciated!

Chris
  • 183
  • 2
  • 11
  • 1
    That is because your y-axis is a log scale. If you change the y-axis to a linear one, you'll see that the fit is actually quite good. – Roald Feb 28 '20 at 20:52
  • Amazing - thank you. Have changed y-axis to linear and converted my y values to log(y) and it's spot on now! – Chris Feb 28 '20 at 21:57

1 Answers1

1

That is because your y-axis is a log scale. If you change the y-axis to a linear one, you'll see that the fit is actually quite good.

Roald
  • 2,459
  • 16
  • 43