forked from dmitryikh/leaves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xgblinear.go
53 lines (43 loc) · 1.23 KB
/
xgblinear.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
package leaves
// xgLinear is XGBoost model (gblinear)
type xgLinear struct {
NumFeature int
nRawOutputGroups int
BaseScore float64
Weights []float32
}
func (e *xgLinear) NEstimators() int {
return 1
}
func (e *xgLinear) NRawOutputGroups() int {
return e.nRawOutputGroups
}
func (e *xgLinear) adjustNEstimators(nEstimators int) int {
// gbliearn has only one estimator per class
return 1
}
func (e *xgLinear) NFeatures() int {
return e.NumFeature
}
func (e *xgLinear) Name() string {
return "xgboost.gblinear"
}
func (e *xgLinear) NLeaves() []int {
return []int{}
}
func (e *xgLinear) predictInner(fvals []float64, nIterations int, predictions []float64, startIndex int) {
for k := 0; k < e.nRawOutputGroups; k++ {
predictions[startIndex+k] = e.BaseScore + float64(e.Weights[e.nRawOutputGroups*e.NumFeature+k])
for i := 0; i < e.NumFeature; i++ {
predictions[startIndex+k] += fvals[i] * float64(e.Weights[e.nRawOutputGroups*i+k])
}
}
}
func (e *xgLinear) predictLeafIndicesInner(fvals []float64, nEstimators int, predictions []float64, startIndex int) {
// TODO: may be we should return an error here
}
func (e *xgLinear) resetFVals(fvals []float64) {
for j := 0; j < len(fvals); j++ {
fvals[j] = 0.0
}
}