44 "fmt"
55)
66
7- // LGEnsemble ..
7+ // LGEnsemble is LightGBM model (ensemble of trees)
88type LGEnsemble struct {
99 Trees []LGTree
1010 MaxFeatureIdx uint32
@@ -14,6 +14,10 @@ func (e *LGEnsemble) NTrees() int {
1414 return len (e .Trees )
1515}
1616
17+ // Predict calculates prediction from ensembles of trees. Only `nTrees` first
18+ // trees will be used. If `len(fvals)` is not enough function will quitely
19+ // return 0.0. Note, that result is a raw score (before sigmoid function
20+ // transformation and etc)
1721func (e * LGEnsemble ) Predict (fvals []float64 , nTrees int ) float64 {
1822 if e .MaxFeatureIdx + 1 > uint32 (len (fvals )) {
1923 return 0.0
@@ -31,6 +35,11 @@ func (e *LGEnsemble) Predict(fvals []float64, nTrees int) float64 {
3135 return ret
3236}
3337
38+ // PredictCSR calculates predictions from ensembles of trees. `indptr`, `cols`,
39+ // `vals` represent data structures from Compressed Sparse Row Matrix format (see CSRMat).
40+ // Only `nTrees` first trees will be used.
41+ // Note, that result is a raw score (before sigmoid function transofrmation and etc).
42+ // Note, `predictions` slice should be properly allocated on call side
3443func (e * LGEnsemble ) PredictCSR (indptr []uint32 , cols []uint32 , vals []float64 , predictions []float64 , nTrees int ) {
3544 fvals := make ([]float64 , e .MaxFeatureIdx + 1 )
3645 for i := 0 ; i < len (indptr )- 1 ; i ++ {
@@ -50,6 +59,11 @@ func (e *LGEnsemble) PredictCSR(indptr []uint32, cols []uint32, vals []float64,
5059 }
5160}
5261
62+ // PredictDense calculates predictions from ensembles of trees. `vals`, `rows`,
63+ // `cols` represent data structures from Rom Major Matrix format (see DenseMat).
64+ // Only `nTrees` first trees will be used.
65+ // Note, that result is a raw score (before sigmoid function transofrmation and etc).
66+ // Note, `predictions` slice should be properly allocated on call side
5367func (e * LGEnsemble ) PredictDense (vals []float64 , nrows uint32 , ncols uint32 , predictions []float64 , nTrees int ) error {
5468 if ncols == 0 || e .MaxFeatureIdx > ncols - 1 {
5569 return fmt .Errorf ("incorrect number of columns" )
0 commit comments