-
Notifications
You must be signed in to change notification settings - Fork 0
/
test copy.html
48 lines (43 loc) · 1 KB
/
test copy.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Decision Tree Classifier</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scikit-learn.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js-ml.js"></script>
<script src="https://unpkg.com/js-ml"></script>
</head>
<body>
<div id="result"></div>
<script>
// Load your data from an array
const data = [
[1, 3, 1],
[2, 4, 1],
[3, 1, 0],
[4, 2, 0],
[5, 3, 1],
[6, 1, 0],
[7, 2, 0],
[8, 4, 1],
[9, 2, 0],
[10, 3, 1],
];
// Preprocess your data
const X = data.map(row => [row[0], row[1]]);
const y = data.map(row => row[2]);
// Train a decision tree classifier
const clf = new ml.DecisionTreeClassifier({
criterion: "entropy"
});
clf.train(X, y).then(() => {
setTimeout(() => {
console.log("Training complete.");
}, 0);
});
// Make a prediction
const prediction = clf.predict([[2, 4]]);
console.log(prediction);
</script>
</body>
</html>