I have a small problem to perform TSNE on my dataset, using cosine similarity.
I have calculated the cosine similarity of all of my vectors, so I have a square matrix which contains my cosine similarity :
A = [[ 1 0.7 0.5 0.6 ]
[ 0.7 1 0.3 0.4 ]
[ 0.5 0.3 1 0.1 ]
[ 0.6 0.4 0.1 1 ]]
Then, I'm using TSNE like that :
A = np.matrix([[1, 0.7,0.5,0.6],[0.7,1,0.3,0.4],[0.5,0.3,1,0.1],[0.6,0.4,0.1,1]])
model = manifold.TSNE(metric="precomputed")
Y = model.fit_transform(A)
But I'm not sure that to use precomputed metric keep the sense of my cosine similarity:
#[documentation][1]
If metric is “precomputed”, X is assumed to be a distance matrix
But when I try to use cosine metric, I got an error :
A = np.matrix([[1, 0.7,0.5,0.6],[0.7,1,0.3,0.4],[0.5,0.3,1,0.1],[0.6,0.4,0.1,1]])
model = manifold.TSNE(metric="cosine")
Y = model.fit_transform(A)
raise ValueError("All distances should be positive, either "
ValueError: All distances should be positive, either the metric or
precomputed distances given as X are not correct
So my question is, How is it possible to perform TSNE using cosine metric on an existent dataset (similarity matrix) ?
fit_transform
to transform my input. And the error seems to come from there ... I have coded a small part which doesn't work :from sklearn import manifold import numpy as np A = np.matrix([[1, 0.7,0.5,0.6],[1, 0.7,0.5,0.6],[0.5,0.3,1,0.1],[0.6,0.4,0.1,1]]) model = manifold.TSNE(metric="cosine") Y = model.fit_transform(A)
– Wilkerson