【算法】Cosine similarity

cosine similarity

sent A: 我喜欢看电视,不喜欢看电影

sent B: 我不喜欢看电视,也不喜欢看电影

 

step1: segment

sent A: 我 喜欢 看 电视 不 喜欢 看 电影

sent B: 我 不 喜欢 看 电视,也 不 喜欢 看 电影

 

step2: TF(TF * IDF)

sent A:我 1,喜欢 2,看 2,电视 1,电影 1,不 1,也 0。

sent B:我 1,喜欢 2,看 2,电视 1,电影 1,不 2,也 1。

 

step3: vector

sent A:[1, 2, 2, 1, 1, 1, 0]

sent B:[1, 2, 2, 1, 1, 2, 1]

 

step4: calculate

 

 

posted on 2014-12-12 15:11  有个姑娘叫小芳  阅读(1091)  评论(0编辑  收藏  举报