-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add R^2 statistic for Model #810
Conversation
Codecov Report
@@ Coverage Diff @@
## master #810 +/- ##
=======================================
Coverage 93.87% 93.88%
=======================================
Files 10 9 -1
Lines 3480 3481 +1
=======================================
+ Hits 3267 3268 +1
Misses 213 213
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also thanks for this @newville - two minor comments
lmfit/model.py
Outdated
if self.data is not None and len(self.data) > 1: | ||
sstot = max(tiny, ((self.data - self.data.mean())**2).sum()) | ||
if isinstance(self.residual, np.ndarray) and len(self.residual) > 1: | ||
self.rsquared = 1.0 - (self.residual**2).sum() / sstot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for readability I would prefer the max(tiny, .....)
to be in the line above instead of the sstot
define, but that might be a personal preference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@reneeotten Yeah, I agree. I think I was fighting line length considerations, but readability is not only line length ;)
@@ -137,6 +137,8 @@ def fit_report(inpars, modelpars=None, show_correl=True, min_correl=0.1, | |||
add(f" reduced chi-square = {getfloat_attr(result, 'redchi')}") | |||
add(f" Akaike info crit = {getfloat_attr(result, 'aic')}") | |||
add(f" Bayesian info crit = {getfloat_attr(result, 'bic')}") | |||
if hasattr(result, 'rsquared'): | |||
add(f" R-squared = {getfloat_attr(result, 'rsquared')}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably also add this to fitreport_html_table
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks, I forgot. Will add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@newville looks ready to me for a squash-and-merge
Adds R^2 statistic for Model fits, as discussed in #803.
Description
Type of Changes
Tested on
Verification
Have you