[Tutor] Counting the consistent rankings

Ali Torkamani torkamani at gmail.com
Mon Jul 23 23:11:40 CEST 2012


Hi All,

I want to count how many  (what percentage)  of partial orders are
identical in two lists.  (For example let L1 be the list of ground truth
scores and L2 be the estimated scores for a list of students, I want to
check how many (what percentage) of pairwise orderings (rankings) are
preserved)

I have written the following (inefficient) code, is there anyway in Python
to write it more efficiently?


    S=0;
    A=0;
    n=len(L1)
    for i in range(n):
        for j in range(i+1,n,1):
            A+=1;
            if (L1[i]>L1[j] and L2[i]>L2[j]) or (L1[i]<L1[j] and
L2[i]<L2[j]) or (L1[i]==L1[j] and L2[i]==L2[j]):
                S+=1

    print(100*float(S)/A)


Thanks,

A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120723/5d092187/attachment.html>


More information about the Tutor mailing list