core

package
v0.0.0-...-9fef4a1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2018 License: MIT Imports: 5 Imported by: 3

README

GoDoc

Core package

import "github.com/Applifier/go-xgboost/core"

Example

// create the training data
cols := 3
rows := 5
trainData := make([]float32, cols*rows)
for i := 0; i < rows; i++ {
    for j := 0; j < cols; j++ {
        trainData[(i*cols)+j] = float32((i + 1) * (j + 1))
    }
}

trainLabels := make([]float32, rows)
for i := 0; i < rows; i++ {
    trainLabels[i] = float32(1 + i*i*i)
}

// Create XGDMatrix for training data
matrix, _ := core.XGDMatrixCreateFromMat(trainData, rows, cols, -1)

// Set training labels
matrix.SetFloatInfo("label", trainLabels)

// Create booster
booster, _ := core.XGBoosterCreate([]*core.XGDMatrix{matrix})

// Set booster parameters
booster.SetParam("booster", "gbtree")
booster.SetParam("objective", "reg:linear")
booster.SetParam("max_depth", "5")
booster.SetParam("eta", "0.1")
booster.SetParam("min_child_weight", "1")
booster.SetParam("subsample", "0.5")
booster.SetParam("colsample_bytree", "1")
booster.SetParam("num_parallel_tree", "1")

// perform 200 learning iterations
for iter := 0; iter < 200; iter++ {
    booster.UpdateOneIter(iter, matrix)
}

testData := make([]float32, cols*rows)
for i := 0; i < rows; i++ {
    for j := 0; j < cols; j++ {
        testData[(i*cols)+j] = float32((i + 1) * (j + 1))
    }
}

// Create XGDMatrix for test data
testmat, _ := core.XGDMatrixCreateFromMat(testData, rows, cols, -1)

// Predict
res, _ := booster.Predict(testmat, 0, 0)

fmt.Printf("%+v\n", res)
// output: [1.08002 2.5686886 7.86032 29.923136 63.76062]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSuccessful = errors.New("not succesfull")

ErrNotSuccessful returned when an action fails

Functions

This section is empty.

Types

type XGBooster

type XGBooster struct {
	// contains filtered or unexported fields
}

XGBooster gradient booster

func XGBoosterCreate

func XGBoosterCreate(matrix []*XGDMatrix) (*XGBooster, error)

XGBoosterCreate creates a new booster for a given matrixes

func (*XGBooster) DeleteParam

func (booster *XGBooster) DeleteParam(name string) error

DeleteParam set parameters

func (*XGBooster) LoadModel

func (booster *XGBooster) LoadModel(filePath string) error

LoadModel load model from existing file

func (*XGBooster) Predict

func (booster *XGBooster) Predict(mat *XGDMatrix, optionMask int, ntreeLimit uint) ([]float32, error)

Predict make prediction based on dmat

func (*XGBooster) SaveModel

func (booster *XGBooster) SaveModel(filePath string) error

SaveModel save model into file

func (*XGBooster) SetParam

func (booster *XGBooster) SetParam(name string, value string) error

SetParam set parameters

func (*XGBooster) UpdateOneIter

func (booster *XGBooster) UpdateOneIter(iter int, mat *XGDMatrix) error

UpdateOneIter update the model in one round using dtrain

type XGDMatrix

type XGDMatrix struct {
	// contains filtered or unexported fields
}

XGDMatrix matrix

func XGDMatrixCreateFromMat

func XGDMatrixCreateFromMat(data []float32, nrows int, ncols int, missing float32) (*XGDMatrix, error)

XGDMatrixCreateFromMat create matrix content from dense matrix

func (*XGDMatrix) GetFloatInfo

func (matrix *XGDMatrix) GetFloatInfo(field string) ([]float32, error)

GetFloatInfo get float info vector from matrix

func (*XGDMatrix) GetUIntInfo

func (matrix *XGDMatrix) GetUIntInfo(field string) ([]uint32, error)

GetUIntInfo get uint32 info vector from matrix

func (*XGDMatrix) NumCol

func (matrix *XGDMatrix) NumCol() (uint32, error)

NumCol get number of cols.

func (*XGDMatrix) NumRow

func (matrix *XGDMatrix) NumRow() (uint32, error)

NumRow get number of rows.

func (*XGDMatrix) SetFloatInfo

func (matrix *XGDMatrix) SetFloatInfo(field string, values []float32) error

SetFloatInfo set float vector to a content in info

func (*XGDMatrix) SetGroup

func (matrix *XGDMatrix) SetGroup(group ...uint32) error

SetGroup set label of the training matrix

func (*XGDMatrix) SetUIntInfo

func (matrix *XGDMatrix) SetUIntInfo(field string, values []uint32) error

SetUIntInfo set uint32 vector to a content in info

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL