Skip to content

Commit efb3324

Browse files
authored
Stop using statistics.mode.
Stop using statistics.mode, because it throws an error when there are ties.
1 parent 48f079e commit efb3324

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

learning.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
import math
1212
import random
1313

14-
# XXX statistics.mode is not quite the same as the old utils.mode:
15-
# it insists on there being a unique most-frequent value. Code using mode
16-
# needs to be revisited, or we need to restore utils.mode.
17-
from statistics import mean, mode
18-
from collections import defaultdict
14+
from statistics import mean
15+
from collections import defaultdict, Counter
1916

2017
# ______________________________________________________________________________
2118

19+
def mode(data):
20+
"""Return the most common data item. If there are ties, return any one of them."""
21+
(item, count) = Counter(data).most_common(1)
22+
return item
2223

2324
def rms_error(predictions, targets):
2425
return math.sqrt(ms_error(predictions, targets))

0 commit comments

Comments
 (0)