-
Notifications
You must be signed in to change notification settings - Fork 409
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
Weighted Pearson, Spearman, and R2 score #1759
base: master
Are you sure you want to change the base?
Weighted Pearson, Spearman, and R2 score #1759
Conversation
I’m adding a weighted version of Pearson right now and updated the I tried debugging |
if weights.ndim == preds.ndim: | ||
raise ValueError( | ||
f"Expected `n_samples` of preds to match the length of `weights`," | ||
f" but got {preds.shape[0]} and {len(weights)}." | ||
) | ||
else: | ||
raise ValueError("") |
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.
if weights.ndim == preds.ndim: | |
raise ValueError( | |
f"Expected `n_samples` of preds to match the length of `weights`," | |
f" but got {preds.shape[0]} and {len(weights)}." | |
) | |
else: | |
raise ValueError("") | |
if weights.shape != preds.shape: | |
raise ValueError( | |
f"Expected `n_samples` of preds to match the length of `weights`," | |
f" but got {preds.shape[0]} and {len(weights)}." | |
) |
I think this check needs to be even more restrictive such that they can be multiplied together or else I am missing something.
Also I do not think there should be an else
statement.
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 split the check into single and multi-output cases:
- if single output (
preds.ndim=1
),preds
andweights
must have same shape - if multi-output (
preds.ndim=2
)- if
weights.ndim=2
,preds
andweights
must have same shape - if
weight.ndim=1
,preds.shape[0]
has to be equal tolen(weights)
- if
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.
Okay, that makes sense to me, but the implementation then needs to reflect that. Currently, if weight.ndim=1
and preds.ndim=2
the code will just fail with an value error.
def _scipy_pearson(preds, target): | ||
if preds.ndim == 2: | ||
return [pearsonr(t.numpy(), p.numpy())[0] for t, p in zip(target.T, preds.T)] | ||
return pearsonr(target.numpy(), preds.numpy())[0] | ||
|
||
|
||
def _weighted_pearson(preds, target, weights): | ||
if preds.ndim == 2: | ||
return [pearsonr(t.numpy(), p.numpy())[0] for t, p in zip(target.T, preds.T)] |
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.
should this not depend on weights
?
@matsumotosan I have taken care of the testing now, such that inputs gets correctly send to the respective input. |
@matsumotosan @SkafteNicki, how is it going here? Could we have it for the next 1.1 release? |
The docstring for |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
* fix * changelog
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
* fix * changelog
6a8603b
to
e2e800f
Compare
for more information, see https://pre-commit.ci
@matsumotosan run rebase from master so pls check if I resolved all conflict property... |
if cond: | ||
mx_new = (n_prior * mean_x + preds.sum(0)) / (n_prior + n_obs) | ||
my_new = (n_prior * mean_y + target.sum(0)) / (n_prior + n_obs) | ||
if weights is None: | ||
mx_new = (n_prior * mean_x + preds.sum(0)) / (n_prior + n_obs) | ||
my_new = (n_prior * mean_y + target.sum(0)) / (n_prior + n_obs) | ||
else: | ||
mx_new = (n_prior * mean_x + torch.matmul(weights, preds)) / (n_prior + n_obs) | ||
my_new = (n_prior * mean_y + torch.matmul(weights, target)) / (n_prior + n_obs) | ||
else: | ||
mx_new = preds.mean(0) | ||
my_new = target.mean(0) | ||
if weights is None: | ||
mx_new = preds.mean(0) | ||
my_new = target.mean(0) | ||
else: | ||
mx_new = torch.matmul(weights, preds) / weights.sum() | ||
my_new = torch.matmul(weights, target) / weights.sum() |
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.
Can we rather have have if weights
is NOne to make it full of ones to have no effect but the code simpler
d0a5568
to
9fc79ae
Compare
What does this PR do?
Fixes #1235
Before submitting
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.
Did you have fun?
Make sure you had fun coding 🙃