DMatrix
public class DMatrix
Data class used with Booster.
Data is encapsulation of DMatrixHandle, internal structure used by XGBoost, which is optimized for both memory efficiency and training speed.
-
Name of dataset, for example, “train”.
Declaration
Swift
public var name: String -
Pointer to underlying DMatrixHandle.
Declaration
Swift
public let dmatrix: DMatrixHandle? -
Initialize Data with an existing DMatrixHandle pointer.
Declaration
Parameters
nameName of dataset.
dmatrixDMatrixHandle pointer.
featuresArray describing features in this dataset.
labelSets label after DMatrix initialization.
weightSets weight after DMatrix initialization.
baseMarginSets baseMargin after DMatrix initialization.
labelLowerBoundSets labelLowerBound after DMatrix initialization.
labelUpperBoundSets labelUpperBound after DMatrix initialization.
-
init(name:from: shape: features: label: weight: baseMargin: labelLowerBound: labelUpperBound: missingValue: threads: ) Initialize Data.
Declaration
Swift
public convenience init( name: String, from data: FloatData, shape: Shape, features: [Feature]? = nil, label: FloatData? = nil, weight: FloatData? = nil, baseMargin: FloatData? = nil, labelLowerBound: FloatData? = nil, labelUpperBound: FloatData? = nil, missingValue: Float = Float.greatestFiniteMagnitude, threads: Int = 0 ) throwsParameters
nameName of dataset.
fromValues source.
shapeShape of resulting DMatrixHandle, needs to be of rank two, e.g. [row, column].
featuresNames and types of features.
labelSets label after DMatrix initialization.
weightSets weight after DMatrix initialization.
baseMarginSets baseMargin after DMatrix initialization.
labelLowerBoundSets labelLowerBound after DMatrix initialization.
labelUpperBoundSets labelUpperBound after DMatrix initialization.
missingValueValue in the input data which needs to be present as a missing value.
threadsNumber of threads to use for loading data when parallelization is applicable. If 0, uses maximum threads available on the system.
-
init(name:from: features: label: weight: baseMargin: labelLowerBound: labelUpperBound: missingValue: threads: ) Initialize Data.
Declaration
Swift
public convenience init( name: String, from: FloatData & ShapeData, features: [Feature]? = nil, label: FloatData? = nil, weight: FloatData? = nil, baseMargin: FloatData? = nil, labelLowerBound: FloatData? = nil, labelUpperBound: FloatData? = nil, missingValue _: Float = Float.greatestFiniteMagnitude, threads: Int = 0 ) throwsParameters
nameName of dataset.
fromData with shape comfortance.
featuresNames and types of features.
labelSets label after DMatrix initialization.
weightSets weight after DMatrix initialization.
baseMarginSets baseMargin after DMatrix initialization.
labelLowerBoundSets labelLowerBound after DMatrix initialization.
labelUpperBoundSets labelUpperBound after DMatrix initialization.
missingValueValue in the input data which needs to be present as a missing value.
threadsNumber of threads to use for loading data when parallelization is applicable. If 0, uses maximum threads available on the system.
-
init(name:from: format: useCache: features: labelColumn: label: weight: baseMargin: labelLowerBound: labelUpperBound: silent: fileQuery: ) Initialize Data from file.
Declaration
Swift
public convenience init( name: String, from file: String, format: DataFormat, useCache: Bool = false, features: [Feature]? = nil, labelColumn: Int? = nil, label: FloatData? = nil, weight: FloatData? = nil, baseMargin: FloatData? = nil, labelLowerBound: FloatData? = nil, labelUpperBound: FloatData? = nil, silent: Bool = true, fileQuery: [String] = [] ) throwsParameters
nameName of dataset.
fromFile to laod from.
formatFormat of input file.
useCacheUse external memory.
featuresNames and types of features.
labelColumnWhich column is for label.
labelSets label after DMatrix initialization.
weightSets weight after DMatrix initialization.
baseMarginSets baseMargin after DMatrix initialization.
labelLowerBoundSets labelLowerBound after DMatrix initialization.
labelUpperBoundSets labelUpperBound after DMatrix initialization.
silentWhether print messages during construction.
fileQueryAdditional parameters that will be appended to the file path as query.
-
Save DMatrixHandle to binary file.
Declaration
Swift
public func save( to path: String, silent: Bool = true ) throwsParameters
toFile path.
silentWhether print messages during construction.
-
Save feature map compatible with XGBoost`s inputs.
Declaration
Swift
public func saveFeatureMap( to path: String ) throwsParameters
toPath where feature map will be saved.
-
Load previously saved feature map.
Declaration
Swift
public func loadFeatureMap( from path: String ) throwsParameters
fromPath to the feature map.
-
Declaration
Swift
public func rowCount() throws -> IntReturn Value
The number of rows.
-
Declaration
Swift
public func columnCount() throws -> IntReturn Value
The number of columns.
-
Declaration
Swift
public func shape() throws -> ShapeReturn Value
The shape of dmatrix, i.e. (rowCount(), columnCount()).
-
Slice and return a new Data that only contains
indexes.Declaration
Swift
public func slice( indexes: Int32Data, newName: String? = nil, allowGroups: Bool = false ) throws -> DMatrixParameters
indexesArray of indices to be selected.
newNameNew name of the returned Data.
allowGroupsAllow slicing of a matrix with a groups attribute.
Return Value
A new dmatrix class containing only selected indexes.
-
Slice and return a new Data that only indexes from given range..
Declaration
Swift
public func slice( indexes: Range<Int32>, newName: String? = nil, allowGroups: Bool = false ) throws -> DMatrixParameters
indexesRange of indices to be selected.
newNameNew name of the returned Data.
allowGroupsAllow slicing of a matrix with a groups attribute.
Return Value
A new DMatrix class containing only selected indexes.
-
Set uint type property into the DMatrixHandle.
Declaration
Swift
public func setUIntInfo( field: String, values: UInt32Data ) throwsParameters
fieldThe field name of the information.
valuesThe array of data to be set.
-
Set float type property into the DMatrixHandle.
Declaration
Swift
public func setFloatInfo( field: String, values: FloatData ) throwsParameters
fieldThe field name of the information.
valuesThe array of data to be set.
-
Get unsigned integer property from the DMatrixHandle.
Declaration
Swift
public func getUIntInfo( field: String ) throws -> [UInt32]Parameters
fieldThe field name of the information.
Return Value
An array of unsigned integer information of the data.
-
Get float property from the DMatrixHandle.
Declaration
Swift
public func getFloatInfo( field: String ) throws -> [Float]Parameters
fieldThe field name of the information.
Return Value
An array of float information of the data.
-
Set uint type property into the DMatrixHandle.
Declaration
Swift
public func set( field: UIntField, values: UInt32Data ) throwsParameters
fieldThe field name of the information.
valuesThe array of data to be set.
-
Set float type property into the DMatrixHandle.
Declaration
Swift
public func set( field: FloatField, values: FloatData ) throwsParameters
fieldThe field name of the information.
valuesThe array of data to be set.
-
Save names and types of features.
Declaration
Swift
public func set( features: [Feature]? ) throwsParameters
featuresOptional array of features.
-
Declaration
Swift
public func features(defaultPrefix: String = "f") throws -> [Feature]Return Value
Features of data, generates universal names with quantitative type if not previously set by user.
-
Declaration
Swift
public func get(field: FloatField) throws -> [Float]Return Value
An array of float information of the data.
-
Declaration
Swift
public func get(field: UIntField) throws -> [UInt32]Return Value
An array of uint information of the data.
View on GitHub
DMatrix Class Reference