Source

orange-modelmaps / archive / compare_matrices.py

Full commit
#import orange
import OWDistanceFile
#import scipy.stats

smx1, lbl1, data1 = OWDistanceFile.readMatrix(r'c:\Users\miha\Projects\res\metamining\dst\zoo-projections-10-spearman.dst')
smx2, lbl2, data2 = OWDistanceFile.readMatrix(r'c:\Users\miha\Projects\res\metamining\dst\zoo-projections-10-pearson.dst')
k = 5
c = []
taus = []
for i in range(smx1.dim):
    neighbours1 = [(smx1[i,j], j) for j in range(smx1.dim) if i != j]
    knn1 = set([b for a,b in sorted(neighbours1)[:k]])
    neighbours2 = [(smx2[i,j], j) for j in range(smx2.dim) if i != j]
    knn2 = set([b for a,b in sorted(neighbours2)[:k]])
    #c.append(len(knn1.intersection(knn2)) / float(len(knn1.union(knn2))))
    c.append(len(knn1.intersection(knn2)) / float(k))
    

        
print sum(c) / float(len(c))