0

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. 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!

Mr. T
  • 11,960
  • 10
  • 32
  • 54
apappy
  • 1
  • 1
  • Welcome to SO. Your code is not runnable by others as `xdata` is not defined. Please review these links: [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples), how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) – piterbarg Nov 12 '20 at 23:44
  • After playing around with the number of data points I realized the curved line is the first fit and the rest are linear regressions coming from the later data. – apappy Nov 12 '20 at 23:45

0 Answers0