-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticlassification.go
76 lines (62 loc) · 1.76 KB
/
multiclassification.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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), "multiclassification.cbm")
// Initialize CatBoostClassifier
model, err := cb.LoadFullModelFromFile(modelPath)
if err != nil {
log.Fatalln(err)
}
// Initialize data
floats := [][]float32{{1996, 197}, {1968, 37}, {2002, 77}, {1948, 59}}
cats := [][]string{{"winter"}, {"winter"}, {"summer"}, {"summer"}}
// Get batch predicted RawFormulaVal
preds, err := model.Predict(floats, cats)
if err != nil {
log.Fatalln(err)
}
predsMulti := model.Transform(preds)
fmt.Printf("Preds `RawFormulaVal`: %.8f\n", predsMulti)
// 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 probabilities for each class
model.SetPredictionType(cb.Probablity)
preds, err = model.Predict(floats, cats)
if err != nil {
log.Fatalln(err)
}
predsMulti = model.Transform(preds)
fmt.Printf("Preds `Probability`: %.8f\n", predsMulti)
// Get single predicted probabilities for each class
pred, err = model.PredictSingle(floats[0], cats[0])
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Pred `Probability`: %.8f\n", pred)
// Get batch predicted classes
model.SetPredictionType(cb.Class)
preds, err = model.Predict(floats, cats)
if err != nil {
log.Fatalln(err)
}
predsMulti = model.Transform(preds)
fmt.Printf("Preds `Class`: %.0f\n", predsMulti)
// Get single predicted classes
pred, err = model.PredictSingle(floats[0], cats[0])
if err != nil {
log.Fatalln(err)
}
fmt.Printf("Pred `Class`: %.0f\n", pred)
}