-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 837 Bytes
/
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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"github.com/MiXaiLL76/naivebayes"
)
// Data class
type Data struct {
Features [][]float64 `json:"features"`
Prediction []int `json:"prediction"`
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
func main() {
gnb := naivebayes.GaussianNB{}
weight, err := ioutil.ReadFile("predictor.json")
checkErr(err)
err = gnb.SetWeight(weight)
checkErr(err)
bytesData, err := ioutil.ReadFile("data.json")
checkErr(err)
var testData Data
err = json.Unmarshal(bytesData, &testData)
checkErr(err)
prediction := gnb.Predict(testData.Features)
pass := 0
for i, val := range testData.Prediction {
if val == prediction[i] {
pass++
}
}
if len(prediction) == pass {
log.Println("Test passed")
} else {
log.Println("Test not passed")
}
}