Easy (though not very), just change it to:
popt, pcov = curve_fit(goal.__call__, xdata, ydata)
Interestingly, numpy forces you to pass an object to the curve_fit function, not an arbitrary callable ...
quickly checking the source for curve_fit , it seems like another workaround might be:
popt,pcov = curve_fit(goal, xdata, ydata, p0=[1]*5)
Here p0 is the initial assumption for the fitting parameters. The problem is that scipy checks the arguments of the function so that it knows how many parameters to use, unless you actually provide parameters as an initial assumption. Here, since we have 5 parameters, my initial guess is a list of all of them with a length of 5. ( scipy is used by default, unless you also give an assumption).
source share