Package ml.dmlc.xgboost4j.java
Class DMatrix
java.lang.Object
ml.dmlc.xgboost4j.java.DMatrix
DMatrix for xgboost.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionDMatrix
(float[] data, int nrow, int ncol) create DMatrix from dense matrixDMatrix
(float[] data, int nrow, int ncol, float missing) create DMatrix from dense matrixprotected
DMatrix
(long handle) used for DMatrix sliceDMatrix
(long[] headers, int[] indices, float[] data, DMatrix.SparseType st) Deprecated.DMatrix
(long[] headers, int[] indices, float[] data, DMatrix.SparseType st, int shapeParam) Create DMatrix from Sparse matrix in CSR/CSC format.Create DMatrix by loading libsvm file from dataPathCreate DMatrix from iterator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
protected void
finalize()
private static float[]
flatten
(float[][] mat) flatten a mat to arrayfloat[]
Get base margin of the DMatrix.private float[]
getFloatInfo
(String field) long
Get the handleprivate int[]
getIntInfo
(String field) float[]
getLabel()
get label valuesfloat[]
get weight of the DMatrixlong
rowNum()
get the row number of DMatrixvoid
saveBinary
(String filePath) save DMatrix to filePathvoid
setBaseMargin
(float[] baseMargin) Set base margin (initial prediction).void
setBaseMargin
(float[][] baseMargin) Set base margin (initial prediction).void
setGroup
(int[] group) Set group sizes of DMatrix (used for ranking)void
setLabel
(float[] labels) set label of dmatrixvoid
setWeight
(float[] weights) set weight of each instanceslice
(int[] rowIndex) Slice the DMatrix and return a new DMatrix that only contains `rowIndex`.
-
Field Details
-
handle
protected long handle
-
-
Constructor Details
-
DMatrix
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
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
create DMatrix from dense matrix- Parameters:
data
- data valuesnrow
- number of rowsncol
- number of columns- Throws:
XGBoostError
- native error
-
DMatrix
create DMatrix from dense matrix- Parameters:
data
- data valuesnrow
- number of rowsncol
- number of columnsmissing
- the specified value to represent the missing value- Throws:
XGBoostError
-
DMatrix
protected DMatrix(long handle) used for DMatrix slice
-
-
Method Details
-
setLabel
set label of dmatrix- Parameters:
labels
- labels- Throws:
XGBoostError
- native error
-
setWeight
set weight of each instance- Parameters:
weights
- weights- Throws:
XGBoostError
- native error
-
setBaseMargin
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
Set base margin (initial prediction).- Throws:
XGBoostError
-
setGroup
Set group sizes of DMatrix (used for ranking)- Parameters:
group
- group size as array- Throws:
XGBoostError
- native error
-
getFloatInfo
- Throws:
XGBoostError
-
getIntInfo
- Throws:
XGBoostError
-
getLabel
get label values- Returns:
- label
- Throws:
XGBoostError
- native error
-
getWeight
get weight of the DMatrix- Returns:
- weights
- Throws:
XGBoostError
- native error
-
getBaseMargin
Get base margin of the DMatrix.- Throws:
XGBoostError
-
slice
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
get the row number of DMatrix- Returns:
- number of rows
- Throws:
XGBoostError
- native error
-
saveBinary
save DMatrix to filePath -
getHandle
public long getHandle()Get the handle -
flatten
private static float[] flatten(float[][] mat) flatten a mat to array -
finalize
protected void finalize() -
dispose
public void dispose()
-