How to find initial guess for leastsq function in Python?
No, you can't really calculate an initial guess.
You'll just have to make an educated guess, and that really depends on your data and model.
If the initial guess affects the fitting, there is likely something else going on; you're probably getting stuck in local minima. Your model may be too complex, or your data range may be so large that you run into floating point precision limits and the fitting algorithm can't detect any changes for parameter changes. The latter can often be avoided by normalizing your data (and model), or, for example, using log(-log) space instead of linear space.
Or avoid leastsq altogether, and use a different minimization method (which will likely be much slower, but may produce overall better and more consistent results), such as the Nelder-Mead amoebe method.
I have a dataset for which I need to fit the plot. I am using leastsq() for fitting. However, currently I need to give initial guess values manually which is really affecting the fitting. Is there any way to first calculate the initial guess values which I can pass in leastsq()?