-
Notifications
You must be signed in to change notification settings - Fork 10
/
isolation.go
50 lines (46 loc) · 1 KB
/
isolation.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
package main
import (
"fmt"
"math/rand"
randomforest "github.com/malaschitz/randomForest"
"github.com/petar/GoMNIST"
)
func main() {
rand.Seed(1)
TREES := 1000
size := 60000
xsize := 28 * 28
labels, err := GoMNIST.ReadLabelFile("examples/train-labels-idx1-ubyte.gz")
if err != nil {
panic(err)
}
_, _, imgs, err := GoMNIST.ReadImageFile("examples/train-images-idx3-ubyte.gz")
if err != nil {
panic(err)
}
if len(labels) != size || len(imgs) != size {
panic("Wrong size")
}
//train
forest := randomforest.Forest{}
x := make([][]float64, size)
l := make([]int, size)
for i := 0; i < size; i++ {
x[i] = make([]float64, xsize)
for j := 0; j < xsize; j++ {
x[i][j] = float64(imgs[i][j])
l[i] = int(labels[i])
}
}
forest.Data = randomforest.ForestData{X: x, Class: l}
forest.MaxDepth = 30
forest.Train(TREES)
//ISOLATION
isolations, mean, stddev := forest.IsolationForest()
for i, d := range isolations {
if d < (mean - 1.6*stddev) {
fmt.Println(i, (d-mean)/stddev)
}
}
//
}