What am I doing wrong when calculating similarity according to Pearson correlation

24 Views Asked by At

Given the following formula, I need to calculate how similar two vectors are. $$s(i, j) = \frac { ri ⋅ rj } {∥ri ∥2∥rj ∥2}$$

my vectors:

$$ri = [1,3, 5,5, 4] $$ $$rj = [2,4,2,3,4,3,5] $$

I started to solve the problem by calculating the numerator as follows: $$ (1x2) + (3x4) + (5x2) +(5x3) + (4x4) + (3) + (5) =$$ $$ 2 + 12 +10 + 15 +16 + 3+5 = 63 $$

So now I need to calculate the denominator. So I started by calculating the magnitude of the vectors as follwos: $$r1$$ $$ ∥ri∥ = (1)^2 + (3)^2 + (5)^2 + (5)^2 + (4)^2 $$ $$ ∥ri∥ = 1 + 9 + 25 + 25 + 16 = {\sqrt{76}} = 8,71 $$ $$rj$$ $$ ∥rj∥ = (2)^2 + (4)^2 + (2)^2 + (3)^2 + (4)^2 + (3)^2 + (5)^2 $$ $$ ∥rj∥ = 4 + 16 + 4 + 9 + 16 + 9 + 25= {\sqrt{83}} = 9,11 $$

So, now I already have:

$$s(i, j) = \frac {63 } {(8,71) 2 (9,11) 2}$$

$$s(i, j) = \frac {63 } {17,42 . 18,22} = 0,1984 $$

My professor said the answer is 0.41. However, as you can see, I can get a result of 0.19. What am I doing wrong? Can anyone help? Also, I can't quite figure out what these 2s in the denominator mean. Do I need to multiply them?