You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yes, I read the instructions and I am sure this is a GitHub Issue.
Description
The ModelResult instance gained from Model.fit() has the wrong rsquared attribute. Floating point R^2 statistic, defined for data y and best-fit model f as R^2=1-\sum{(y_i-f_i)^2/(y_i-y_mean)^2}. In model.py, line1482, the code to calculate rsquared attribute is self.rsquared = 1.0 - (self.residual**2).sum()/max(tiny, sstot), but in your code, residual is not best_fit-data but the return value of the objective function when using the best-fit values of the parameters, which is (best_fit-data)*weights. if weights=None in Model.fit(), the two are same, otherwise they are different. This is a small bug, but I don't know if there's other part where you use residual as best_fit-data. Hope you check your code carefully. Thank you for all your contributions.
should replace self.residual (which, as you say, is weighted) with dat-self.best_fit (probably moving the calculation of self.best_fit that is just a few lines below.
If you are willing and able to make a Pull Request, that would be great. If not, let us know and we'll fix this very soon.
Thank you for reply, but I'm sorry I don't know how to make a Pull Request. Actually, I just register my Github account today, and I'm afraid I'll mess it up if I make a Pull Request.
First Time Issue Code
Yes, I read the instructions and I am sure this is a GitHub Issue.
Description
The
ModelResult
instance gained fromModel.fit()
has the wrongrsquared
attribute. Floating pointR^2
statistic, defined for datay
and best-fit modelf
asR^2=1-\sum{(y_i-f_i)^2/(y_i-y_mean)^2}
. In model.py, line1482, the code to calculatersquared
attribute isself.rsquared = 1.0 - (self.residual**2).sum()/max(tiny, sstot)
, but in your code,residual
is notbest_fit-data
but the return value of the objective function when using the best-fit values of the parameters, which is(best_fit-data)*weights
. ifweights=None
inModel.fit()
, the two are same, otherwise they are different. This is a small bug, but I don't know if there's other part where you useresidual
asbest_fit-data
. Hope you check your code carefully. Thank you for all your contributions.A Minimal, Complete, and Verifiable example
Fit report:
Error message:
There's no error message, but as you see,
ModelResult
gives the wrongrsquared
.Version information
Python: 3.12.0 (tags/v3.12.0:0fb18b0, Oct 2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
lmfit: 1.2.2, scipy: 1.11.3, numpy: 1.26.0,asteval: 0.9.31, uncertainties: 3.1.7
The text was updated successfully, but these errors were encountered: