用余弦相似性在不同情节结束的两种计算T-SNE图的方法,但是该方法似乎是相同的

发布于 2025-02-07 13:32:58 字数 948 浏览 2 评论 0原文

在过去的一个小时中,我一直在研究这个问题,但似乎找不到问题... 我有一份文章列表,我想查看哪些文章彼此相似。

我通过计算文章的TF-IDF向量之间的余弦相似性并制作结果的T-SNE图。我以两种方式做到了这一点,但令我惊讶的是,这些地块彼此截然不同,而且我看不出哪一个是正确的。

在示例中,TFDOC是TF-IDF。

from sklearn.metrics.pairwise import cosine_similarity
from sklearn import manifold

X = cosine_similarity(tfdoc, tfdoc)
model = manifold.TSNE(random_state=1, metric="precomputed")
Y = model.fit_transform(X) 

绘制后,这将导致:

”在此处输入图像说明“

但是当我使用此代码时:

from sklearn.manifold import TSNE

tsne = TSNE(random_state=1, metric="cosine")

embs = tsne.fit_transform(tfdoc)

<

a href =“ https://i.sstatic.net/kcwk8.png” “> “在此处输入图像说明”

有人知道这里的区别到底是什么?

提前致谢!!

I have been looking at this for the past hour but can not seem to find the problem...
I have a list of articles on which I want to see which articles are similar to each other.

I have done this by computing the cosine similarities between the TF-IDF vectors of the articles and making a t-SNE plot of the result. I have done this in 2 ways but what surprised me is that the plots are very different from each other, and I do not see which one is correct.

In the examples, tfdoc is the TF-IDF.

from sklearn.metrics.pairwise import cosine_similarity
from sklearn import manifold

X = cosine_similarity(tfdoc, tfdoc)
model = manifold.TSNE(random_state=1, metric="precomputed")
Y = model.fit_transform(X) 

when plotted, this results in:

enter image description here

But when I use this code:

from sklearn.manifold import TSNE

tsne = TSNE(random_state=1, metric="cosine")

embs = tsne.fit_transform(tfdoc)

It results in:

enter image description here

Does someone know what the difference here exactly is?

Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2025-02-14 13:32:58

第一个测试使用余弦相似性,而第二个测试使用余弦距。通常,较大的余弦距离意味着较小的余弦相似性。

The first test uses cosine-similarity, whereas the second uses cosine-distance. Normally, larger cosine distances means smaller cosine similarity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文