Hierarchical clustering with similarity matrix
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi there,
I have a similarity matrix that I would like to use as the input of the function linkage. However, this takes as an input only the a dissimilarity/distance matrix. Do you know any way by which I can manage to run a hierarchical clustering in Matlab using my similarity matrix?
Cheers!
댓글 수: 0
답변 (1개)
Akanksha Shrimal
2022년 4월 26일
Hi,
It is my understanding that you want to compute Hierarchical Clustering with ‘linkage’ function in MATLAB using a similarity matrix.
The ‘linkage’ function in MATLAB takes input as distance vector to compute clusters.
Given a similarity matrix s, we can compute the dissimilarity matrix of s by
ds = 1 – s
This dissimilarity matrix is then converted into a vector form that 'linkage' accepts using 'squareform'.
X = squareform(ds)
Now you can apply 'linkage' with X using ‘complete’ method for calculating distance between clusters.
Z = linkage(X,’complete’)
Hope this helps.
댓글 수: 1
Umar
2024년 8월 9일
편집: Umar
2024년 8월 9일
Hi @Akanksha Shrimal,
I executed the code above following your mentioned instructions,”Given a similarity matrix s, we can compute the dissimilarity matrix of s by
ds = 1 – s
This dissimilarity matrix is then converted into a vector form that 'linkage' accepts using 'squareform'.
X = squareform(ds) “
and encountered an error in code. Please see attached.
![](/matlabcentral/answers/uploaded_files/1750009/IMG_7384.jpeg)
Am I missing something?
The definition of similarity matrix can be found here,
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!