-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassifier.go
56 lines (46 loc) · 1.21 KB
/
classifier.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
54
55
56
package main
import (
"fmt"
"log"
"path"
"path/filepath"
"runtime"
cb "github.com/mirecl/catboost-cgo/catboost"
)
func main() {
_, fileName, _, _ := runtime.Caller(0)
modelPath := path.Join(filepath.Dir(fileName), "classifier.cbm")
// Initialize CatBoostClassifier
model, err := cb.LoadFullModelFromFile(modelPath)
if err != nil {
log.Fatalln(err)
}
// Initialize data
floats := [][]float32{{2, 4, 6, 8, 5}, {1, 4, 50, 60, 5}}
cats := [][]string{{"a", "b"}, {"a", "d"}}
// Get batch predicted RawFormulaVal
preds, err := model.Predict(floats, cats)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Preds `RawFormulaVal`: %.8f\n", preds)
// Get single predicted RawFormulaVal
pred, err := model.PredictSingle(floats[0], cats[0])
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Pred `RawFormulaVal`: %.8f\n", pred)
// Get batch predicted Probability
model.SetPredictionType(cb.Probablity)
preds, err = model.Predict(floats, cats)
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Preds `Probability`: %v\n", preds)
// Get single predicted Probability
pred, err = model.PredictSingle(floats[0], cats[0])
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Pred `Probability`: %.8f\n", pred)
}