Skip to content

PearsonCorrcoef always zero when validation batch size is one. #286

Discussion options

You must be logged in to vote

When you call
self.val_correlation(y_pred, y_true)
you are calculating the correlation on that batch. If the batch size is only 1 then the correlation will always be 0. What you of cause want to do is to calculate the correlation over the hole validation set as pearsons is a global metric. You should therefore do something like this:

def validation_step(self, batch, batch_idx):
    y_pred, y_true, loss = self.common_step(batch, batch_idx)
    self.val_correlation.update(y_pred, y_true)

def validation_epoch_end(self, outputs):
    corr = self.val_correlation.compute()
    self.log_dict({"val_correlation": corr})

Replies: 5 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by edgarriba
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@edgarriba
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed working as intended
4 participants
Converted from issue

This discussion was converted from issue #271 on June 09, 2021 10:51.