Lightning-AI / torchmetrics

Machine learning metrics for distributed, scalable PyTorch applications.
https://lightning.ai/docs/torchmetrics/
Apache License 2.0
2.13k stars 404 forks source link

Add weights for the pearson, spearman, and r2_score #1235

Open DomInvivo opened 2 years ago

DomInvivo commented 2 years ago

🚀 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.

Borda commented 2 years ago

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

DomInvivo commented 1 year ago

@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.

matsumotosan commented 1 year ago

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

justusschock commented 1 year ago

@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 :)

stale[bot] commented 1 year ago

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.