Skip to content

Instantly share code, notes, and snippets.

@tibaes
Created April 5, 2021 18:46
Show Gist options
  • Save tibaes/030e965ea8a3207722a9d9357428867d to your computer and use it in GitHub Desktop.
Save tibaes/030e965ea8a3207722a9d9357428867d to your computer and use it in GitHub Desktop.
Fitting a logistic curve
from scipy.optimize import curve_fit
def logistic(x, x0, L, k):
return L / (1.0 + np.exp(-k*(x - x0)))
def resample(X, y) -> np.array:
X = np.array(X)
y = np.array(y)
bounds = (0, [1.0, np.max(y), 1000])
popt, pcov = curve_fit(logistic, X, y, bounds=bounds)
return [logistic(x=x, x0=popt[0], L=popt[1], k=popt[2]) for x in X]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment