This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
Add Covariance and PearsonCorrelation metrics #1684
Merged
nelson-liu
merged 10 commits into
allenai:master
from
nelson-liu:pearson_correlation_metric
Aug 29, 2018
Merged
Add Covariance and PearsonCorrelation metrics #1684
nelson-liu
merged 10 commits into
allenai:master
from
nelson-liu:pearson_correlation_metric
Aug 29, 2018
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
joelgrus
approved these changes
Aug 29, 2018
def __init__(self) -> None: | ||
self._total_prediction_mean = 0.0 | ||
self._total_label_mean = 0.0 | ||
self._total_comoment = 0.0 |
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.
nit: it's very hard for my brain not to look at comoment
and feel like someone made a typo in comment
, which is jarring. would you consider co_moment
instead? 😀
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.
(feel free to tell me I'm being a crazy person)
gabrielStanovsky
pushed a commit
to gabrielStanovsky/allennlp
that referenced
this pull request
Sep 7, 2018
This PR implements an online algorithm for calculating Covariance and the sample Pearson correlation coefficient. This was actually nontrivial, I mostly referenced the tensorflow [streaming_covariance metric](https://github.com/tensorflow/tensorflow/blob/4dcfddc5d12018a5a0fdca652b9221ed95e9eb23/tensorflow/contrib/metrics/python/ops/metric_ops.py#L3127-L3264) in implementing this. Their implementation is a vectorized version of the weighted algorithm [on this wikipedia page](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online) The tests simply ensure that the streaming Covariance and PearsonCorrelation match up with what numpy would calculate, which I believe is a reasonable correctness check.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements an online algorithm for calculating Covariance and the sample Pearson correlation coefficient.
This was actually nontrivial, I mostly referenced the tensorflow streaming_covariance metric in implementing this. Their implementation is a vectorized version of the weighted algorithm on this wikipedia page
The tests simply ensure that the streaming Covariance and PearsonCorrelation match up with what numpy would calculate, which I believe is a reasonable correctness check.