-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliffsDelta.py
More file actions
31 lines (26 loc) · 754 Bytes
/
cliffsDelta.py
File metadata and controls
31 lines (26 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Taken from https://github.com/neilernst/cliffsDelta
from __future__ import division
def cliffsDelta(lst1, lst2):
"""Returns Cliff's delta"""
m, n = len(lst1), len(lst2)
lst2 = sorted(lst2)
j = more = less = 0
for repeats, x in runs(sorted(lst1)):
while j <= (n - 1) and lst2[j] < x:
j += 1
more += j*repeats
while j <= (n - 1) and lst2[j] == x:
j += 1
less += (n - j)*repeats
d = (more - less) / (m*n)
return d
def runs(lst):
"""Iterator, chunks repeated values"""
for j, two in enumerate(lst):
if j == 0:
one, i = two, 0
if one != two:
yield j - i, one
i = j
one = two
yield j - i + 1, two