Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. def cosine_sim(x1,x2):
  2.     sum_arr = x1+x2
  3.     f11 = len(np.where(sum_arr == 2)[0])
  4.     #return f11/(np.linalg.norm(x1) * np.linalg.norm(x2))
  5.     return np.dot(x1.T, x2)/(np.linalg.norm(x1) * np.linalg.norm(x2))
  6.  
  7. def jaccard_sim(x1,x2):
  8.     sum_arr = x1+x2
  9.     f11 = len(np.where(sum_arr == 2)[0])
  10.     f00 = len(np.where(sum_arr == 0)[0])
  11.     return f11/(len(x1) - f00)
  12.  
  13. def smc_sim(x1, x2):
  14.     sum_arr = x1+x2
  15.     f11 = len(np.where(sum_arr == 2)[0])
  16.     f00 = len(np.where(sum_arr == 0)[0])
  17.     return (f00 + f11)/(len(x1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement