-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathID3Tree.hs
41 lines (35 loc) · 1.29 KB
/
ID3Tree.hs
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
32
33
34
35
36
37
38
39
40
module ID3Tree where
import Data.List
import Data.Ord(comparing)
import DataStructures
import UtilityFunctions
import ReadWrite
import ID3Functions
buildTree :: TargetName -> DomainValue -> Set -> Tree Set
buildTree targetname domainvalue set
| setpurity set targetname == 0 =
let
targetvalue = head $ getTargetValues set targetname
in
Leaf domainvalue targetvalue set
| (length set == 1) || (maxInformationGain set targetname == 0)=
let
targetvalues = getTargetValues set targetname
totaltargetvalues = fromIntegral $ length targetvalues
targetvaluesgrouped = group $ sort $ targetvalues
targetvaluescounted = map (\x -> (head x, (fromIntegral $ length x)/totaltargetvalues)) targetvaluesgrouped
in
UncertainLeaf domainvalue targetvaluescounted set
| otherwise =
let
splitset = splitSet set targetname
attributename = fst splitset
newsets = snd splitset
in
Node domainvalue attributename (map (\x -> buildTree targetname (fst x) (snd x)) newsets) set
id3Tree :: Set -> TargetName -> Tree Set
id3Tree set targetname =
let
domainvalue = "root"
in
buildTree targetname domainvalue set