I am trying to fit a logistic regression model to a dataset that has multiple measurements. When I put my data through CurveFit, Lmfit StepModel/Model, I get the same number of best fit curves as the number of sets of measurements rather than one model that best fits the dataset overall. Is there a way to get a single output?
Here is my code for the Step-like model for simplicity. I was looking at the first 500 rows of data to have a less cluttered figure. The x data are timesteps in the form of integers ranging between 0 and 20 corresponding to gas levels in the y data (anywhere from -200 to 15000).
from lmfit.models import StepModel
step_mod = StepModel(form='logistic')
pars = step_mod.make_params(amplitude=15000,center=10,sigma=20)
n=500
x = xdata.head(n)
y = ydata.head(n)
out = step_mod.fit(y, pars, x=x)
plt.plot(x, y, 'b.')
plt.plot(x, out.init_fit, 'k--', label='initial fit')
plt.plot(x, out.best_fit, 'r-', label='best fit')
plt.legend(loc='best')
plt.show()
The resulting figure. I want a single red line for all the blue datapoints.
Is there a way to do this? It seems like it should be a multivariate logistic regression but I can find any information online. I'm also confused why it can't treat the data size separate from the output size. Any help would be appreciated!