Functions

The following functions are available globally.

  • Train a booster with given parameters.

    Declaration

    Swift

    public func xgboost(params: [Param] = [],
                        data: DMatrix,
                        numRound: Int = 10,
                        evalSet: [(DMatrix, String)]? = nil,
                        fnObj: FuncObj? = nil,
                        fnEval: FuncEval? = nil,
                        modelFile: String? = nil,
                        callbacks: [XGBCallback]? = nil) throws -> Booster

    Parameters

    data

    DMatrix

    numRound

    Int - Number of boosting iterations.

    params

    [(String, String)] - Booster parameters. It was changed from Dictionary to array of set to enable multiple eval_metric, now it does not need to provide evalMetric for multiple eval_metric. You pass multiple sets for eval_metric in the params array.

    evalSet

    list of tuples (DMatrix, name of the eval data). The validation sets will evaluated during training.

    fnObj

    pass an optional custom objective function.

    fnEval

    pass an optional custom evaluation function.

    modelFile

    String - If the modelFile param is provided, it will load the model from that file.

    callbacks

    pass optional callbacks, which should conform to the XGBCallback protocol

    Return Value

    Booster

  • Cross-validation with given parameters

    Declaration

    Swift

    public func xgboostCV(params: [Param] = [],
                          data: DMatrix,
                          numRound: Int = 10,
                          nFold: Int = 3,
                          fnObj: FuncObj? = nil,
                          fnEval: FuncEval? = nil,
                          callbacks: [XGBCallback]? = nil) throws -> CVResult

    Parameters

    params

    [(String, String)] - Booster parameters. It was changed from Dictionary to array of set to enable multiple eval_metric, now it does not need to provide evalMetric for multiple eval_metric. You pass multiple sets for eval_metric in the params array.

    data

    DMatrix

    numRound

    Int - Number of boosting iterations.

    nFold

    number of cross validation folds

    fnObj

    pass an optional custom objective function.

    fnEval

    pass an optional custom evaluation function.

    callbacks

    pass optional callbacks, which should conform to the XGBCallback protocol

    Return Value

    CVResult

  • Undocumented

    Declaration

    Swift

    public func xgboostVersion() -> (major: Int, minor: Int, patch: Int)
  • Have to set verbosity parameters to 2(info)/3(debug) xgboost to make it print log messages. The passing closure should have 1 positional parameter, which is the log message.

    Declaration

    Swift

    public func xgbRegisterLogCallback(_ fn: (@convention(c) (UnsafePointer<Int8>?) -> Void)?)