-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitanic.js
43 lines (33 loc) · 1.22 KB
/
Titanic.js
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
var DecisionTree = require('decision-tree');
var training_data = [
{"color":"blue", "shape":"square", "liked":false},
{"color":"red", "shape":"square", "liked":false},
{"color":"blue", "shape":"circle", "liked":true},
{"color":"red", "shape":"circle", "liked":true},
{"color":"blue", "shape":"hexagon", "liked":false},
{"color":"red", "shape":"hexagon", "liked":false},
{"color":"yellow", "shape":"hexagon", "liked":true},
{"color":"yellow", "shape":"circle", "liked":true}
];
var test_data = [
{"color":"blue", "shape":"hexagon", "liked":false},
{"color":"red", "shape":"hexagon", "liked":false},
{"color":"yellow", "shape":"hexagon", "liked":true},
{"color":"yellow", "shape":"circle", "liked":true}
];
var class_name = "liked";
var features = ["color", "shape"];
var dt = new DecisionTree(class_name, features);
dt.train(training_data);
var dt = new DecisionTree(training_data, class_name, features);
var predicted_class = dt.predict({
color: "blue",
shape: "hexagon"
});
var accuracy = dt.evaluate(test_data);
var treeJson = dt.toJSON();
var treeJson = dt.toJSON();
var preTrainedDecisionTree = new DecisionTree(treeJson);
console.log(accuracy)
console.log(preTrainedDecisionTree)
console.log(predicted_class)