Cosine similarity gives us the sense of cos angle between vectors. When vector are in same direction, cosine similarity is 1 while in case of perpendicular, it is 0. It is given by (1- cosine distance).
So this recipe is a short example on what cosine similarity is and how to calculate it. Let's get started.
from scipy import spatial
Let's pause and look at these imports. We have imported spatial library from scipy class Scipy contains bunch of scientific routies like solving differential equations.
Let us create two vectors list.
We have first calucated cosine distance and the subtracting it from 1 has given us cosine similarity
Simply use print function to print new appended list.
Once we run the above code snippet, we will see: