According to the doc , optimization with curve_fit gives you
The optimal values ββfor the parameters, so that the sum of the quadratic error from f (xdata, * popt) - ydata is minimized
Then use optimize.leastsq
import scipy.optimize p,cov,infodict,mesg,ier = optimize.leastsq( residuals,a_guess,args=(x,y),full_output=True,warning=True)
with this for residuals :
def residuals(a,x,y): return yf(x,a)
residuals is a method that returns the difference between the true output of y and the output of the model, with f model, a parameters (s), x input.
The optimize.leastsq method returns a lot of information that you can use to calculate RSquared and RMSE yourself. For RSQuared you can do
ssErr = (infodict['fvec']**2).sum() ssTot = ((yy.mean())**2).sum() rsquared = 1-(ssErr/ssTot )
Learn more about infodict['fvec']
In [48]: optimize.leastsq? ... infodict