DMatrix

public class DMatrix

DMatrix is a wrap of the internal data structure DMatrix that used by XGBoost. You can construct from a file (libsvm (default) or csv) or [Float]. To load csv file, specify uri parameter ‘path_to_csv?format=csv’ or set the format param to ‘csv’.

  • If the DMatrix is initialized, by simply checking if the DMatrixHandle is non-nil.

    Declaration

    Swift

    public var initialized: Bool { get }
  • The number of rows in the DMatrix

    Declaration

    Swift

    public var numRow: UInt64 { get }
  • The number of cols in the DMatrix

    Declaration

    Swift

    public var numCol: UInt64 { get }
  • The shape of the DMatrix, [numRow, numCol]

    Declaration

    Swift

    public var shape: [UInt64] { get }
  • The labels of the DMatrix

    Declaration

    Swift

    public var label: [Float] { get set }
  • The weight of the DMatrix

    Declaration

    Swift

    public var weight: [Float] { get set }
  • Not used base_margin for conforming to Swift naming convention

    Declaration

    Swift

    public var baseMargin: [Float] { get set }
  • Use baseMargin instead

    Declaration

    Swift

    public var base_margin: [Float] { get set }
  • Set group info for the DMatrix

    Declaration

    Swift

    public func setGroup(_ newValue: [UInt])
  • Construct DMatrix from file

    Declaration

    Swift

    public init(fromFile fname: String,
                format: String = "libsvm",
                label: [Float]? = nil,
                weight: [Float]? = nil,
                baseMargin: [Float]? = nil,
                silent: Bool = true) throws
  • Construct DMatrix from array of Float, by setting shape, missing values will be filled in automatically or by setting missing (Float.infinity as default).

    Declaration

    Swift

    public init(fromArray array: [Float],
                shape: (row: Int, col: Int),
                label: [Float]? = nil,
                weight: [Float]? = nil,
                baseMargin: [Float]? = nil,
                missing NaValue: Float = -.infinity) throws
  • Save the DMatrix to file

    Declaration

    Swift

    public func saveBinary(toFile fname: String, silent: Bool = true) throws

    Parameters

    toFile

    filename

    silent

    if print debug infomation

  • Slice the DMatrix by using an array of row indexes, return a DMatrix of the selected rows.

    Declaration

    Swift

    public func slice(rows idxSet: [Int], allowGroups: Bool = false) -> DMatrix?
  • Slice the DMatrix by using a range of row indexes, return a DMatrix of the selected rows.

    Declaration

    Swift

    public func slice(rows idxSet: Range<Int>, allowGroups: Bool = false) -> DMatrix?