# Create similarity matrix

I have a training set and a testing set of vectors. All the vectors are labeled.

For each labeled vector in the testing set, there are 3 vectors in the training set with the same label.

I'm using the cosine distance in order to calculate the similarity between the elements in the vectors. In the picture, we can see the results of applying the cosine distance similarity in a subset of 6 vectors from the testing set and 18 from the training set.

Now, I would like to create a similarity matrix of the labels. So, in this case, I'd need a matrix of 6x6 dimension, but I am not sure how to transform this matrix of scores to a similarity matrix.

• What do you mean by a similarity matrix? Do you mean a matrix with similarity measures in the cells - en.wikipedia.org/wiki/Similarity_measure? Sep 15, 2017 at 12:38
• With similarity matrix I mean this. I would like to get the similarity between the labels Sep 15, 2017 at 12:43

You have two scenarios here.

• The vectors with the same labels are close to each other.

Then, what you can do is perhaps use the distance between the two closest/furthest elements in the groups with label x and the group with label y.

You could also create an average vector for each label, and then simply get the distance between these.

• Your vectors are not close to each other

This is not an issue. Here, what you'll want to see, is if for instance, for each vector with label x, there is a vector with label y close to it.

To do that, you could use the Earth Mover's Distance which gives you a single score when you are trying to see how far two "groups of things" are.