0

I want to calculate the cosine similarity score for some graph nodes from a given vector embedding file. How do I calculate the score now for each node in python? I believe using the scikit-learn, we can solve this.

I have generated an edge list from a series of graph nodes. Then I converted the edge list into a vector graph embedding using node2vec.

I expect the output to show the cosine similarity score for each node

   1 -> 0.2
   2 -> 0.4
   3 -> 0.5
   .
   .

I am sorry if I was not able to explain my problem properly because I am new to data science. I can clarify in the comments.

Rocky4
  • 25
  • 6
  • 2
    Possible duplicate of [Cosine Similarity between 2 Number Lists](https://stackoverflow.com/questions/18424228/cosine-similarity-between-2-number-lists) – Masoud Keshavarz Jul 22 '19 at 05:24
  • @MasoudKeshavarz But Sir this only takes a number list into consideration and finds the cosine similarity between the two. I want to find the cosine similarity for each of the graph nodes. – Rocky4 Jul 22 '19 at 05:42

1 Answers1

0

The function cosine_similarity accepts a data matrix as input.

It then returns a matrix of pairwise similarities.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194
  • But does it show the cosine similarity value for each pair? – Rocky4 Jul 22 '19 at 11:24
  • It does not "show" anything. It returns a matrix. If you want to print a particular format, write code to print that format. You example above does not make sense, as cosine similarities are between two nodes, not one. – Has QUIT--Anony-Mousse Jul 22 '19 at 22:23