1
$\begingroup$

Suppose I have two vectors, both of which are probabilities of something (sum to 1). Under what circumstances will correlation (say Pearson corr.) and similarity (say cosine sim.) differ largely?

I found one question one this but it does not touch one this specific question.

$\endgroup$
  • $\begingroup$ Both correlation and cosine similarity/distance are measures of similarity/distance. Is your question specifically about Pearson's correlation and cosine similarity? $\endgroup$ – Pieter Aug 5 '17 at 22:09
  • $\begingroup$ @Pieter Yes, let's take Pearson corr and cosine sim. as an example. $\endgroup$ – Zhiya Aug 6 '17 at 13:01
2
$\begingroup$

They are in general pretty different in magnitude.

Let $v = (1/n, 1/n, 1/n, ... 1/n)$ be an n-dim probability vector.

Then $v$ has a correlation of 1 with itself, but its cosine similarity score with itself is only $1/n$.

Another example:

let $v = (.1, .9)$ and $w = (.9, .1)$. Then the correlation between v and w is -1 but the cosine similarity between them is .18.

Any probability vectors will have a non-negative cosine similarity score, but may have a negative Pearson correlation.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! But how should I interpret when two probability vectors have high cosine similarity (e.g., >0.9) but negative Pearson correlation (around -.2)? $\endgroup$ – Zhiya Aug 14 '17 at 3:49
  • $\begingroup$ Can you give me an example of two such probability vectors? Thanks $\endgroup$ – Rachel Kogan Aug 19 '17 at 19:44
  • $\begingroup$ Sorry for my late reply. Here it is: u=(0.086455, 0.081696, 0.07411, 0.082895, 0.086318, 0.085153, 0.087153, 0.085869, 0.083544, 0.088836, 0.079762, 0.078209); v=(0.084606, 0.090245, 0.103638, 0.06136, 0.091619, 0.077643, 0.062884, 0.082069, 0.081827, 0.090805, 0.079354, 0.093951) $\endgroup$ – Zhiya Sep 8 '17 at 16:15
  • $\begingroup$ No. The dot product of those vectors is approx .08, and the correlation is approx 90%. $\endgroup$ – Rachel Kogan Sep 23 '17 at 18:29
  • $\begingroup$ I dont think so. Here are the result: scipy.stats.pearsonr(u,v) gives (-0.43695954986949204, 0.15550155101173249); from sklearn.metrics.pairwise import cosine_similarity; cosine_similarity(u,v) gives array([[ 0.98606257]]) $\endgroup$ – Zhiya Sep 25 '17 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.