torchmetrics icon indicating copy to clipboard operation
torchmetrics copied to clipboard

Add weights for the pearson, spearman, and r2_score

Open DomInvivo opened this issue 2 years ago • 5 comments

🚀 Feature

We can provide a weight Tensor to the regression coefficients, such as pearson, spearman, and r2_score

Motivation

It should be relatively simple to add weights to these computations. And it can be useful in many contexts, including masking by providing 0-weights, or adding more weights to the relevant sample/target pairs.

Pitch

Adding weights parameter in pearson, spearman, and r2_score. The parameter weights should be either None, 1D ,or 2D.

Alternatives

None

Additional context

See weighted pearsonr. For the spearmanr, it should be identical, since spearman is the correlation of the rank.

For the r2_score, there exist some implementations for example in sklearn, but it would be better to provide either a 1D or 2D matrix, and it would be broadcasted to the same shape as preds / target. instead of forcing sample_weight to be 1D.

DomInvivo avatar Sep 23 '22 22:09 DomInvivo

Sounds good to me, @DomInvivo would you interested in implementing it? cc: @SkafteNicki

Borda avatar Oct 19 '22 12:10 Borda

@Borda It's no longer a priority for me, I found a way to achieve what I needed since I only needed weights of 1 and 0. Unfortunately, I do not have time at the moment but could consider it later.

DomInvivo avatar Oct 31 '22 19:10 DomInvivo

@Borda is this still available? I would be interested in working on it.

matsumotosan avatar Jan 10 '23 02:01 matsumotosan

@matsumotosan Yes it is. Feel free to gibe it a shot and we would appreciate a contribution. If you're getting stuck somewhere let us know. Also open a draft PR as early as possible so that we can review early on :)

justusschock avatar Jan 10 '23 09:01 justusschock

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '23 17:08 stale[bot]