Created
April 5, 2021 18:46
-
-
Save tibaes/030e965ea8a3207722a9d9357428867d to your computer and use it in GitHub Desktop.
Fitting a logistic curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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