XGBoost-Node APIs

September 11, 2017 · View on GitHub

Class

XGMatrix
XGModel
Result

Function

XGMatrix
matrix(data, row, col, missing = NaN)XGMatrix
restoreMatrix(file)XGMatrix
matrixFromCSC(data, indptr, indices, n = 0)XGMatrix
matrixFromCSR(data, indptr, indices, n = 0)XGMatrix
XGModel
XGModel(file)XGModel
XGModel.predict(xgmatrix, mask = 0, ntree = 0)Result
XGModel.predictAsync(xgmatrix, mask = 0, ntree = 0, cb: (err, res: Float32Array | null) => {})
Result

XGMatrix

Kind: object - input matrix for XGModel

FieldTypeDescription
matrixinternalreadonly property
errorErrorerror status

matrix(data, row, col, missing) ⇒ XGMatrix

Kind: global function Returns: XGMatrix - xgboost matrix

ParamTypeDescription
dataFloat32Arrayinput matrix with row-major order
rowIntegermatrix row
colIntegermatrix col
missingNumber = NaNmissing value place holder
const xgboost = require('xgboost');
const input = new Float32Array([
  5.1,  3.5,  1.4,  0.2, // class 0
  6.6,  3. ,  4.4,  1.4, // class 1
  5.9,  3. ,  5.1,  1.8  // class 2
]);
const mat = new xgboost.matrix(input, 3, 4);

XGMatrix.col() ⇒ Result

Kind: member function Returns: Result - return matrix column size

mat.col();

XGMatrix.row() ⇒ Result

Kind: member function Returns: Result - return matrix row size

mat.row();

restoreMatrix(file) ⇒ XGMatrix

Kind: global function Returns: XGMatrix - xgboost matrix

ParamTypeDescription
filestringinput matrix file path
const matFromFile = xgboost.restoreMatrix('test/data/xgmatrix.bin');

matrixFromCSC(data, indptr, indices, n) ⇒ XGMatrix

Kind: global function Returns: XGMatrix - xgboost matrix

ParamTypeDescription
dataFloat32Arrayinput matrix
indptrUint32Arraypointer to col headers
indicesUint32Arrayfindex
nInteger = 0number of rows; when it's set to 0, then guess from data
// [
//   1, 2, 3, 1,
//   0, 1, 2, 3,
//   0, 1, 1, 1,
// ]
const sparseCSC = xgboost.matrixFromCSC(
  new Float32Array([1, 2, 1, 1, 3, 2, 1, 1, 3, 1]),
  new Uint32Array([0, 1, 4, 7, 10]),
  new Uint32Array([0, 0, 1, 2, 0, 1, 2, 0, 1, 2]),
  0);

matrixFromCSR(data, indptr, indices, n) ⇒ XGMatrix

Kind: global function Returns: XGMatrix - xgboost matrix

ParamTypeDescription
dataFloat32Arrayinput matrix
indptrUint32Arraypointer to row headers
indicesUint32Arrayfindex
nInteger = 0number of columns; when it's set to 0, then guess from data
// [
//   1, 2, 3, 1,
//   0, 1, 2, 3,
//   0, 1, 1, 1,
// ]
const sparseCSR = xgboost.matrixFromCSR(
  new Float32Array([1, 2, 3, 1, 1, 2, 3, 1, 1, 1]),
  new Uint32Array([0, 4, 7, 10]),
  new Uint32Array([0, 1, 2, 3, 1, 2, 3, 1, 2, 3]),
  0);

XGModel

Kind: object - Trained XGModel

FieldTypeDescription
modelinternalreadonly property
errorErrorerror status

XGModel(file) ⇒ XGModel

Kind: global function Returns: XGModel - xgboost model

ParamTypeDescription
filestringmodel file path
const model = xgboost.XGModel('test/data/iris.xg.model');

XGModel.predict(xgmatrix, mask = 0, ntree = 0) ⇒ Result

Kind: member function Returns: Result - prediction result with Float32Array

ParamTypeDescription
matrixXGMatrixinput matrix
maskInteger = 0options taken in prediction, possible values,
0:normal prediction,
1:output margin instead of transformed value,
2:output leaf index of trees instead of leaf value, note leaf index is unique per tree,
4:output feature contributions to individual predictions
ntreeInteger = 0limit number of trees used for prediction,
this is only valid for boosted trees when the parameter is set to 0,
we will use all the trees
model.predict(mat);

XGModel.predictAsync(xgmatrix, mask = 0, ntree = 0, cb: (err, res: Float32Array | null) => {})

Kind: member function

ParamTypeDescription
matrixXGMatrixinput matrix
maskInteger = 0options taken in prediction, possible values,
0:normal prediction,
1:output margin instead of transformed value,
2:output leaf index of trees instead of leaf value, note leaf index is unique per tree,
4:output feature contributions to individual predictions
ntreeInteger = 0limit number of trees used for prediction,
this is only valid for boosted trees when the parameter is set to 0,
we will use all the trees
cbFunctioncallback function to accept error status and a Float32Array result
model.predictAsync(mat, 0, 0, (err, res) => {
  console.log(err);
  console.log(res);
});

Result

Kind: object

FieldTypeDescription
valueFloat32Array | numberprediction result or method result
errorErrorerror status