1 parent 48f079e commit efb3324Copy full SHA for efb3324
1 file changed
learning.py
@@ -11,14 +11,15 @@
11
import math
12
import random
13
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
+from statistics import mean
+from collections import defaultdict, Counter
19
20
# ______________________________________________________________________________
21
+def mode(data):
+ """Return the most common data item. If there are ties, return any one of them."""
+ (item, count) = Counter(data).most_common(1)
22
+ return item
23
24
def rms_error(predictions, targets):
25
return math.sqrt(ms_error(predictions, targets))
0 commit comments