在scikit-learn中将共现矩阵转换为MDS的不相似矩阵 [英] Convert co-occurrence matrix to dissimilarity matrix for MDS in scikit-learn

查看:68
本文介绍了在scikit-learn中将共现矩阵转换为MDS的不相似矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单词共现矩阵,如下所示.我想使用MDS缩小尺寸并将其绘制出来.在sklearn中有一个函数 model = MDS(n_components = 2,差异='precomputed',random_state = 1)并应用模型 output = model.fit_transform(input)我的理解是输入应该是一个不相似矩阵,而不是我所拥有的相似度矩阵.那是对的吗?我可以使用一个函数来转换该同时出现的相异性矩阵吗?我对此很陌生.非常感谢您的帮助.

I have a matrix of word co-occurrence, like below. I'd like to use MDS to reduce the dimension and plot it. In sklearn there's a function model = MDS(n_components=2, dissimilarity='precomputed', random_state=1) and to apply the model output = model.fit_transform(input)My understanding is the input should be a dissimilarity matrix instead of the similarity one that I have. Is that correct? Is there a function that I could use to convert this co-occurrence dissimilarity matrix? I'm quite new to this. Many thanks for your help.

co-occurrence matrix :
        word1       word2      word3 ...
word1.    0           1          3
word2     1           0          5
word3     3           5          1
...

推荐答案

可能为时已晚,但我可能要提出一个答案.

It might be too late, but I might have an answer to propose.

我使用了一个相似度矩阵(对角线中全为1,这不是您的情况),并找到了一个简单的公式将其转换为一个相似度矩阵:(1个单元格)但是,我的主管发现了另一个公式(我找不到参考文献),该公式似乎可以管理具有不同值的对角线.我在此线程中>,但是我的AWK程序无法应用于您的数据(因为我简化了公式以管理对角线中只有1个的情况).

I used a similarity matrix (full of 1 in the diagonale, which is not your case), and found a simple formula to transform it into a dissimilarity matrix: (1 - cell) However, my supervisor found another formula (I can't find back the reference) which seems to manage a diagonale with different values. I put some details in this thread, but my AWK program can't be applied to your data (as I simplified the formula to manage my case where I only have 1 in diagonale).

最适合您的公式是:

在我的情况下,对角线为1,我将其简化为:

In my case, where the diagonale has 1, I simplified it to :

我希望它能对您有所帮助!:)但是也许我错了.如果是这样,我很想知道细节.

I hope it might help you ! :) But maybe I'm wrong. If that's the case, I'm interested to know the details.

这篇关于在scikit-learn中将共现矩阵转换为MDS的不相似矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆