-
-
Notifications
You must be signed in to change notification settings - Fork 390
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 metric #1274
R2 score metric #1274
Conversation
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.
LGTM, nevertheless, we need to add a few things:
- correct code style with
catalyst-make-codestyle
- tests :)
- Metric API extension?
- Callback API extension?
torch.square(targets.float() - torch.mean(targets.float())) | ||
).view(-1) | ||
residual_sum_of_squares = torch.sum(torch.square(targets.float() - outputs.float())).view(-1) | ||
output = 1 - residual_sum_of_squares / total_sum_of_squares |
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.
I believe, you should do something like max(total_sum_of_squares, eps)
to avoid zero division
import torch | ||
|
||
|
||
def r2_score(outputs: torch.Tensor, targets: torch.Tensor,) -> Sequence[torch.Tensor]: |
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.
mb it should be done like sklearn implementation https://scikit-learn.org/stable/modules/generated/sklearn.metrics.r2_score.html ?
I mean, it seems cool to have possibility to calculate r2 score of tensors with shape [bs, num_outputs] right in torch
plus, sample_weight
might be useful
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.
btw, could you please add all of them to the required __init__
s?
""" | ||
y_true = torch.tensor([2.5, 0.0, 2, 8]) | ||
y_pred = torch.tensor([3, -0.5, 2, 7]) | ||
val = r2_squared(y_true, y_pred) |
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.
you have r2_squared(outputs: torch.Tensor, targets: torch.Tensor)
, rather than targets, outputs
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.
Whoops
Pull request has been modified.
Pull request has been modified.
Before submitting (checklist)
catalyst-make-codestyle && catalyst-check-codestyle
(pip install -U catalyst-codestyle
).make check-docs
?pytest .
?latest
andminimal
requirements?Description
Related Issue
Type of Change
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
FAQ
Please review the FAQ before submitting an issue: