Clauric
Clauric

Reputation: 1886

Find point on sigmoid curve

Perhaps a very simple problem, but I can't seem to find an answer that works.

I am plotting a series of values that returns a sigmoid curve below: Sigmoid curve

The code that was used is (from User88484):

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

p0 = [max(po_array), np.median(sp_array), 1, min(po_array)]

popt, pcov = curve_fit(sigmoid, sp_array, po_array, p0, method='dogbox')

print("Popt:", popt)
print()
print("Pcov:", pcov)

This returns the following values:

Popt: [96.74093921 12.83580801 0.56406601 3.2468077 ]

Pcov: [[ 4.15866152e-01 -3.57909355e-05 -5.46449590e-03 -2.10617443e-01] [-3.57909355e-05 1.81185487e-03 -8.47729461e-06 7.55813943e-03] [-5.46449590e-03 -8.47729461e-06 1.48370347e-04 2.67572376e-03] [-2.10617443e-01 7.55813943e-03 2.67572376e-03 1.75321322e-01]]

Given this, how can I find the y value of the curve, when I am given the x value? i.e. if X = 20, what will the y value be for that point on the curve?

Upvotes: 1

Views: 282

Answers (1)

itaishz
itaishz

Reputation: 711

popt has the fitted values of your defined sigmoid function (L ,x0, k and b). Pass them back to sigmoid:

sigmoid(20, *popt)

The official docs for curve_fit have something very close to it at the end of the example.

Upvotes: 2

Related Questions