Skip to content
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

R2_score for GLM #2696

Merged
merged 2 commits into from
Nov 15, 2017
Merged

R2_score for GLM #2696

merged 2 commits into from
Nov 15, 2017

Conversation

denadai2
Copy link
Contributor

@denadai2 denadai2 commented Nov 8, 2017

Fixes #2564.

Ref #2605.

pymc3/stats.py Outdated
R2_std: standard deviation of the Bayesian R2
"""
e = y_true - y_pred
var_y_est = np.var(y_pred, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to fail if y_predhas dimension 1.

pymc3/stats.py Outdated
@@ -964,3 +964,33 @@ def bfmi(trace):
energy = trace['energy']

return np.square(np.diff(energy)).mean() / np.var(energy)


def r2_score(y_true, y_pred):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about rounding the results by default (maybe 2 decimals) and adding an argument to control this...

pymc3/stats.py Outdated
var_y_est = np.var(y_pred, 1)
var_e = np.var(e, 1)

r2_median = np.median(var_y_est / (var_y_est + var_e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you should assign var_y_est / (var_y_est + var_e) to a variable and then use that variable to compute the mean, median and std

@denadai2
Copy link
Contributor Author

denadai2 commented Nov 8, 2017

thx

@aloctavodia
Copy link
Member

LGTM! In your previous PR you had a test, If possible you should add it again.

@aloctavodia
Copy link
Member

Hi @denadai2 any update on this? Maybe we can skip the test, at least for now. What do you think @twiecki?

@denadai2
Copy link
Contributor Author

@aloctavodia I didn't make any test in the previous pull request :/

@aloctavodia
Copy link
Member

OK, so maybe no test for this PR :-)

@aloctavodia
Copy link
Member

Thanks @denadai2

@aloctavodia aloctavodia merged commit 2b9acb9 into pymc-devs:master Nov 15, 2017
junpenglao pushed a commit that referenced this pull request Nov 24, 2017
Add Bayesian R2 PR #2696.
jordan-melendez pushed a commit to jordan-melendez/pymc3 that referenced this pull request Feb 6, 2018
* R2_score for GLM

* Added round of results and dimension check in r2_score
jordan-melendez pushed a commit to jordan-melendez/pymc3 that referenced this pull request Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants