Square R and absolute sum of squares available scipy.optimize curve_fit?

I use curves using curve_fit. Is there any way to read the coefficient of determination and the absolute sum of squares? Thanks Woodpicker

+6
source share
1 answer

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 -- a dictionary of optional outputs with the keys: 'fvec' : the function evaluated at the output 
+4
source

Source: https://habr.com/ru/post/944607/


All Articles