Professional Documents
Culture Documents
Question 1
In [2]: def plot_2Dpoints(A,B):
import matplotlib.pyplot as plt
ax = plt.axes()
ax.arrow(0.0, 0.0, A[0], A[1], head_width=0.2, head_length=0.2)
plt.annotate(f"A({A[0]},{A[1]})", xy=(A[0], A[1]),xytext=(A[0]+0.5, A[1]))
ax.arrow(0.0, 0.0, B[0], B[1], head_width=0.2, head_length=0.2)
plt.annotate(f"B({B[0]},{B[1]})", xy=(B[0], B[1]),xytext=(B[0]+0.5, B[1]))
plt.xlim(0,10)
plt.ylim(0,10)
plt.show()
plt.close()
---------------------------------------------------------------------------
<ipython-input-2-5882ddd5f4af> in <module>
----> 1 C=np.array([2,1,0,5,2,0])
2 H=np.array([5,4,4,3,0,5])
3 B=np.array([0,1,1,2,4,5])
4 P=np.array([1,3,0,2,0,3])
In [32]: # C-C
CC = cosine_similarity(C.reshape(1,-1),C.reshape(1,-1))
CH = cosine_similarity(C.reshape(1,-1),H.reshape(1,-1))
CP = cosine_similarity(C.reshape(1,-1),P.reshape(1,-1))
CB = cosine_similarity(C.reshape(1,-1),B.reshape(1,-1))
In [34]: HC = cosine_similarity(H.reshape(1,-1),C.reshape(1,-1))
HH = cosine_similarity(H.reshape(1,-1),H.reshape(1,-1))
HP = cosine_similarity(H.reshape(1,-1),P.reshape(1,-1))
HB = cosine_similarity(H.reshape(1,-1),B.reshape(1,-1))
In [36]: PC = cosine_similarity(P.reshape(1,-1),C.reshape(1,-1))
PH = cosine_similarity(P.reshape(1,-1),H.reshape(1,-1))
PP = cosine_similarity(P.reshape(1,-1),P.reshape(1,-1))
PB = cosine_similarity(P.reshape(1,-1),B.reshape(1,-1))
In [38]: BC = cosine_similarity(B.reshape(1,-1),C.reshape(1,-1))
BH = cosine_similarity(B.reshape(1,-1),H.reshape(1,-1))
BP = cosine_similarity(B.reshape(1,-1),P.reshape(1,-1))
BB = cosine_similarity(B.reshape(1,-1),B.reshape(1,-1))
Jaccard similarity
Out[21]: 0.5
In [23]: jaccard_set(C, H)
Out[23]: 0.2
In [24]: jaccard_set(C, B)
Out[24]: 0.5
In [22]: jaccard_set(C, P)
Out[22]: 0.3333333333333333
In [25]: jaccard_set(H, P)
Out[25]: 0.2
In [26]: jaccard_set(H, B)
Out[26]: 0.3333333333333333
In [ ]: