Skip to content

Commit e27de24

Browse files
committed
MOAR WHITESPACE
1 parent 5cc6f62 commit e27de24

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/decision_tree/core.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
(ns decision-tree.core)
22

3+
34
(defn log2 [x]
5+
6+
"Return the base-2 logarithm of x"
7+
48
(/ (Math/log x) (Math/log 2)))
59

10+
611
(defn entropy [alist]
712

813
"Given a list of pairs if (input, output), calculate the entropy of the list with respect to output"
@@ -32,13 +37,16 @@
3237
(recur
3338
(assoc acc o [i]) afn (rest aseq)))))))
3439

40+
3541
(defn all-keys [aseq]
3642

3743
"Given a list of maps, return a set containing all the keys from those maps"
3844

3945
(into #{} (flatten (map keys aseq))))
4046

47+
4148
(defn gain
49+
4250
([k alist]
4351

4452
"Given a key and a list of pairs of (map, output), return the net reduction in entropy caused by partitioning the list according to the values associated with key in the input maps"
@@ -51,6 +59,9 @@
5159
(reduce +
5260
(map #(* (entropy %) (/ (count %) (count alist))) parts))))))
5361

62+
5463
(defn most-informative-key [aseq]
64+
5565
"Given a sequence of pairs of (map, output), return the map key that provides the highest information gain about outout, when used to partition the sequence"
66+
5667
(apply max-key #(gain % aseq) (all-keys (map first aseq))))

0 commit comments

Comments
 (0)