Class DMatrix

java.lang.Object
ml.dmlc.xgboost4j.java.DMatrix

public class DMatrix extends Object
DMatrix for xgboost.
Author:
hzx
  • Field Details

    • handle

      protected long handle
  • Constructor Details

    • DMatrix

      public DMatrix(Iterator<LabeledPoint> iter, String cacheInfo) throws XGBoostError
      Create DMatrix from iterator.
      Parameters:
      iter - The data iterator of mini batch to provide the data.
      cacheInfo - Cache path information, used for external memory setting, can be null.
      Throws:
      XGBoostError
    • DMatrix

      public DMatrix(Iterator<LabeledPoint> iter, String cacheInfo, float missing) throws XGBoostError
      Create DMatrix from iterator.
      Parameters:
      iter - The data iterator of mini batch to provide the data.
      cacheInfo - Cache path information, used for external memory setting, can be null.
      missing - the missing value
      Throws:
      XGBoostError
    • DMatrix

      public DMatrix(String dataPath) throws XGBoostError
      Create DMatrix by loading libsvm file from dataPath
      Parameters:
      dataPath - The path to the data.
      Throws:
      XGBoostError
    • DMatrix

      @Deprecated public DMatrix(long[] headers, int[] indices, float[] data, DMatrix.SparseType st) throws XGBoostError
      Deprecated.
      Create DMatrix from Sparse matrix in CSR/CSC format.
      Parameters:
      headers - The row index of the matrix.
      indices - The indices of presenting entries.
      data - The data content.
      st - Type of sparsity.
      Throws:
      XGBoostError
    • DMatrix

      public DMatrix(long[] headers, int[] indices, float[] data, DMatrix.SparseType st, int shapeParam) throws XGBoostError
      Create DMatrix from Sparse matrix in CSR/CSC format.
      Parameters:
      headers - The row index of the matrix.
      indices - The indices of presenting entries.
      data - The data content.
      st - Type of sparsity.
      shapeParam - when st is CSR, it specifies the column number, otherwise it is taken as row number
      Throws:
      XGBoostError
    • DMatrix

      public DMatrix(long[] headers, int[] indices, float[] data, DMatrix.SparseType st, int shapeParam, float missing, int nthread) throws XGBoostError
      Throws:
      XGBoostError
    • DMatrix

      @Deprecated public DMatrix(float[] data, int nrow, int ncol) throws XGBoostError
      Deprecated.
      Please specify the missing value explicitly using DMatrix(float[],int,int,float)
      create DMatrix from dense matrix
      Parameters:
      data - data values
      nrow - number of rows
      ncol - number of columns
      Throws:
      XGBoostError - native error
    • DMatrix

      public DMatrix(BigDenseMatrix matrix) throws XGBoostError
      create DMatrix from a BigDenseMatrix
      Parameters:
      matrix - instance of BigDenseMatrix
      Throws:
      XGBoostError - native error
    • DMatrix

      public DMatrix(float[] data, int nrow, int ncol, float missing) throws XGBoostError
      create DMatrix from dense matrix
      Parameters:
      data - data values
      nrow - number of rows
      ncol - number of columns
      missing - the specified value to represent the missing value
      Throws:
      XGBoostError
    • DMatrix

      public DMatrix(BigDenseMatrix matrix, float missing) throws XGBoostError
      create DMatrix from dense matrix
      Parameters:
      matrix - instance of BigDenseMatrix
      missing - the specified value to represent the missing value
      Throws:
      XGBoostError
    • DMatrix

      protected DMatrix(long handle)
      used for DMatrix slice
    • DMatrix

      public DMatrix(ColumnBatch columnBatch, float missing, int nthread) throws XGBoostError
      Create the normal DMatrix from column array interface
      Parameters:
      columnBatch - the XGBoost ColumnBatch to provide the array interface of feature columns
      missing - missing value
      nthread - threads number
      Throws:
      XGBoostError
  • Method Details

    • setQueryId

      public void setQueryId(Column column) throws XGBoostError
      Set query id of DMatrix from array interface
      Parameters:
      column - the XGBoost Column to provide the array interface of query id column
      Throws:
      XGBoostError - native error
    • getFeatureNames

      public String[] getFeatureNames() throws XGBoostError
      Get feature names
      Returns:
      an array of feature names to be returned
      Throws:
      XGBoostError
    • setFeatureNames

      public void setFeatureNames(String[] values) throws XGBoostError
      Set feature names
      Parameters:
      values - feature names to be set
      Throws:
      XGBoostError
    • getFeatureTypes

      public String[] getFeatureTypes() throws XGBoostError
      Get feature types
      Returns:
      an array of feature types to be returned
      Throws:
      XGBoostError
    • setFeatureTypes

      public void setFeatureTypes(String[] values) throws XGBoostError
      Set feature types
      Parameters:
      values - feature types to be set
      Throws:
      XGBoostError
    • getGroup

      public int[] getGroup() throws XGBoostError
      Get group sizes of DMatrix
      Returns:
      group size as array
      Throws:
      XGBoostError - native error
    • setGroup

      public void setGroup(int[] group) throws XGBoostError
      Set group sizes of DMatrix (used for ranking)
      Parameters:
      group - group size as array
      Throws:
      XGBoostError - native error
    • setQueryId

      public void setQueryId(int[] qid) throws XGBoostError
      Set query ids (used for ranking)
      Parameters:
      qid - the query ids
      Throws:
      XGBoostError - native error
    • getLabel

      public float[] getLabel() throws XGBoostError
      get label values
      Returns:
      label
      Throws:
      XGBoostError - native error
    • setLabel

      public void setLabel(Column column) throws XGBoostError
      Set label of DMatrix from array interface
      Parameters:
      column - the XGBoost Column to provide the array interface of label column
      Throws:
      XGBoostError - native error
    • setLabel

      public void setLabel(float[] labels) throws XGBoostError
      set label of dmatrix
      Parameters:
      labels - labels
      Throws:
      XGBoostError - native error
    • getWeight

      public float[] getWeight() throws XGBoostError
      get weight of the DMatrix
      Returns:
      weights
      Throws:
      XGBoostError - native error
    • setWeight

      public void setWeight(Column column) throws XGBoostError
      Set weight of DMatrix from array interface
      Parameters:
      column - the XGBoost Column to provide the array interface of weight column
      Throws:
      XGBoostError - native error
    • setWeight

      public void setWeight(float[] weights) throws XGBoostError
      set weight of each instance
      Parameters:
      weights - weights
      Throws:
      XGBoostError - native error
    • getBaseMargin

      public float[] getBaseMargin() throws XGBoostError
      Get base margin of the DMatrix.
      Throws:
      XGBoostError
    • setBaseMargin

      public void setBaseMargin(Column column) throws XGBoostError
      Set base margin of DMatrix from array interface
      Parameters:
      column - the XGBoost Column to provide the array interface of base margin column
      Throws:
      XGBoostError - native error
    • setBaseMargin

      public void setBaseMargin(float[] baseMargin) throws XGBoostError
      Set base margin (initial prediction).

      The margin must have the same number of elements as the number of rows in this matrix.

      Throws:
      XGBoostError
    • setBaseMargin

      public void setBaseMargin(float[][] baseMargin) throws XGBoostError
      Set base margin (initial prediction).
      Throws:
      XGBoostError
    • slice

      public DMatrix slice(int[] rowIndex) throws XGBoostError
      Slice the DMatrix and return a new DMatrix that only contains `rowIndex`.
      Parameters:
      rowIndex - row index
      Returns:
      sliced new DMatrix
      Throws:
      XGBoostError - native error
    • rowNum

      public long rowNum() throws XGBoostError
      get the row number of DMatrix
      Returns:
      number of rows
      Throws:
      XGBoostError - native error
    • nonMissingNum

      public long nonMissingNum() throws XGBoostError
      Get the number of non-missing values of DMatrix.
      Returns:
      The number of non-missing values
      Throws:
      XGBoostError - native error
    • saveBinary

      public void saveBinary(String filePath)
      save DMatrix to filePath
    • getHandle

      public long getHandle()
      Get the handle
    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • dispose

      public void dispose()
    • getQuantileCut

      public DMatrix.QuantileCut getQuantileCut() throws XGBoostError
      Get the Quantile Cut.
      Returns:
      QuantileCut
      Throws:
      XGBoostError