-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (47 loc) · 1.07 KB
/
main.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"DecisionTree/config"
"DecisionTree/data"
"DecisionTree/dataset"
"DecisionTree/tree"
"log"
)
func main() {
var (
attributesFile = "dataset/adult.names"
trainDataFile = "dataset/adult.data"
// testDataFile = "dataset/adult.test"
)
// read data attributes
print("Reading dataset...")
attrTable, err := data.ReadAttributes(attributesFile)
if err != nil {
log.Fatalf("failed to read attributes: %v", err)
return
}
// read training data
trainData, err := data.ReadValues(config.Conf, attrTable, trainDataFile)
if err != nil {
log.Fatalf("failed to read training data: %v", err)
return
}
print("OK\n")
// pre-process data
dataset.PreProcessData(trainData)
// train decision tree
print("Training decision tree...")
t, err := tree.BuildTree(config.Conf, trainData)
if err != nil {
log.Fatalf("failed to build tree: %v", err)
return
}
print("OK\n")
// save tree to file
print("Saving tree...")
err = tree.WriteTreeToFile(t, "tree.json")
if err != nil {
log.Fatalf("failed to save tree: %v", err)
return
}
print("OK\n")
}