1
$\begingroup$

How would one code the following issue:

The columns represent the k groupings from the k cluster algorithms. The rows are the N(N-1)/2 pairs of data points. If an algorithm groups a pair together (i,j) = 1 and 0 otherwise. This results in a binary matrix of size N(N-1)/2 x k. Agreement occurs if algorithms both group a pair of data points together.

How would I calculate, i.e. program, this number for all k combinations of algorithms?

https://link.springer.com/article/10.1007/BF01908075

a in this case represents the pairs of data points grouped together by algorithms 1, 2, 3, ..., k or any other combination of algorithms, for example, 2, 3 and k or 1, 2, 3 and 4. This will allow us to make an UpSet plot:

https://en.wikipedia.org/wiki/UpSet_Plot#:~:text=UpSet%20plots%20are%20a%20data,sets%20(or%20vice%20versa)

and

https://kieranhealy.org/blog/archives/2020/04/16/upset-plots/

$\endgroup$
16
  • $\begingroup$ Comembership confusion matrix - which count is a pair of objects - is a relation between two partitions, a 2x2 frequency table. And I could not understand your setting since I don't see a relation between partitions (columns of you data). Will you explain, in your question, in greater detail what you want to do? $\endgroup$
    – ttnphns
    Dec 6, 2022 at 19:41
  • $\begingroup$ @ttnphns a in this case represents the pairs of data points grouped together by algorithms 1, 2, 3, ..., k or any other combination of algorithms, for example, 2, 3 and k or 1, 2, 3 and 4. This will allow us to make an upSet plot. $\endgroup$ Dec 6, 2022 at 19:48
  • $\begingroup$ @ttnphns Hence, we compare more than two partitions. The binary matrix is preliminary to the frequency table from which we infer a. We would continue doing this until we looped over all algorithm combinations: for k = 3 we have four values for a. $\endgroup$ Dec 6, 2022 at 20:02
  • $\begingroup$ So, you extract some combination of columns from your binary matrix and you want to know how many rows in this extracted submatrix is full of 1s. Right? $\endgroup$
    – ttnphns
    Dec 6, 2022 at 20:02
  • $\begingroup$ @ttnphns Correct $\endgroup$ Dec 6, 2022 at 20:04

1 Answer 1

0
$\begingroup$
cluster=c(2,1,2,0,0,3)                 # kmedioids
cluster=cbind(cluster,c(0,0,0,0,0,1))  # spectral
n=nrow(cluster)
N=n*(n-1)/2                            # aantal paren 
A=matrix(NA,N,2)
for (k in 1:ncol(cluster)){
  rowcounter=1
  for (i in 1:(n-1)){
    for (j in (i+1):n){
      A[rowcounter,k]=cluster[i,k]==cluster[j,k]
      rowcounter=rowcounter+1
    }
  }
}

But unfeasible for Python! Re-write appreciated

$\endgroup$
1
  • 1
    $\begingroup$ Some more commenting in the code, or comments outside the code would make this answer considerably more useful. $\endgroup$ Dec 7, 2022 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.