Python: Data fitting with scipy.optimize.curve_fit with sigma = 0
By : Kity_Pei
Date : March 29 2020, 07:55 AM
Any of those help Why not just drop the variable? If it has zero variance it cannot contribute in any meaningful way to your analysis.

Data fitting using fmin from scipy.optimize under jupyter notebook
By : knie0012
Date : March 29 2020, 07:55 AM
Hope this helps It would be easier to help you if you provided a minimal, complete and verifiable example that reproduced the problem. Without that, we have to guess. In this case, my guess is that you are actually using numpy.fmin, not scipy.optimize.fmin. Add the line code :
from scipy.optimize import fmin
from numpy import *
import numpy as np
from numpy import array, linspace # whatever you actually use
from numpy.random import rand # etc.
from scipy import optimize
p = optimize.fmin(e, p0, args=(x, y))

How to fit a function without fitting the feature of interest using scipy.optimize?
By : user1710010
Date : March 29 2020, 07:55 AM
wish helps you This task is ( assuming I understand the question correctly and as James Phillips pointed out in his comment) quite simple. There are several ways to achieve it, though. Here is one: code :
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
def decay( x, a, b, c ):
return a + b * np.exp(  c * x )
xList = np.linspace( 0, 5, 121 )
yList = np.fromiter( ( .6 * np.exp( ( x  2.25 )**2 / .05 ) + decay( x, .3, 1, .6) + .05 * np.random.normal() for x in xList ), np.float )
takeList = np.concatenate( np.argwhere( np.logical_or(xList < 2., xList > 2.5) ) )
featureList = np.concatenate( np.argwhere( np.logical_and(xList >= 2., xList <= 2.5) ) )
xSubList = xList[ takeList ]
ySubList = yList[ takeList ]
xFtList = xList[ featureList ]
yFtList = yList[ featureList ]
myFit, _ = curve_fit( decay, xSubList, ySubList )
fitList = np.fromiter( ( decay( x, *myFit) for x in xList ), np.float )
cleanY = np.fromiter( ( y  decay( x, *myFit) for x,y in zip( xList, yList ) ), np.float )
fig = plt.figure()
ax = fig.add_subplot( 1, 1, 1 )
ax.plot( xList, yList )
ax.plot( xSubList, ySubList  .1, '' ) ## 0.1 offset for visibility
ax.plot( xFtList, yFtList + .1, ':' ) ## +0.1 offset for visibility
ax.plot( xList, fitList, '.' )
ax.plot( xList, cleanY ) ## feature without background
plt.show()

why scipy.optimize.curce fit function is not fitting the data points correctly and why giving large values of pfit?
By : user3239060
Date : March 29 2020, 07:55 AM
will help you You're using L in your test but 1/L in your fitting; I don't know what you intent, but if you instead use code :
plt.plot(x_data, ff(1/L,*pfit), marker='.', color='red')

Fitting multiple data sets using scipy.optimize with the same parameters
By : Orlando Xavier
Date : March 29 2020, 07:55 AM
will be helpful for those in need I have actually figured it out in the last couple of days. I'll provide the code in case it may be of interest to anyone. I also found that fitting sine functions is pretty hard, so I changed my fake data to Lorentzians. Importing modules and generating fake data, that will be kept in the the lists of lists:

