Last active
December 29, 2015 11:09
-
-
Save isaacsanders/7662186 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn build-id3-tree | |
"Builds an ID3 Decision tree to find target-attr based on the examples" | |
[examples target-attr attributes] | |
(cond | |
(same? target-attr examples) { :label (target-attr (first examples)) } | |
(empty? attributes) { :label (most-common target-attr examples) } | |
:else (let [attr (max-val #(information-gain % examples) attributes) | |
groups (group-by attr examples) | |
child-agent (agent {})] | |
(loop [[value subset] (first groups) | |
others (rest groups)] | |
(do | |
(send child-agent assoc | |
value | |
(if (empty? subset) | |
{ :label (most-common target-attr examples) } | |
(build-id3-tree subset | |
target-attr | |
(without attr attributes)))) | |
(cond | |
(empty? others) { attr child-agent } | |
:else (recur (first others) (rest others)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a lot of data that I am putting in, and I wanted to avoid blocking on the computation.