Can someone give an example of cosine similarity, in a very simple, graphical way?

前端 未结 10 1875
别跟我提以往
别跟我提以往 2020-11-28 17:04

Cosine Similarity article on Wikipedia

Can you show the vectors here (in a list or something) and then do the math, and let us see how it works?

I\'m a begin

10条回答
  •  情话喂你
    2020-11-28 17:52

    Using @Bill Bell example, two ways to do this in [R]

    a = c(2,1,0,2,0,1,1,1)
    
    b = c(2,1,1,1,1,0,1,1)
    
    d = (a %*% b) / (sqrt(sum(a^2)) * sqrt(sum(b^2)))
    

    or taking advantage of crossprod() method's performance...

    e = crossprod(a, b) / (sqrt(crossprod(a, a)) * sqrt(crossprod(b, b)))
    

提交回复
热议问题