secretflow.ml.boost.homo_boost.boost_core package#

Submodules#

secretflow.ml.boost.homo_boost.boost_core.callback module#

Classes:

FedCallbackContainer(callbacks[, metric, is_cv])

Federate version, encapsulates xgboostCallbackContainer.

class secretflow.ml.boost.homo_boost.boost_core.callback.FedCallbackContainer(callbacks: List[TrainingCallback], metric: Optional[Callable] = None, is_cv: bool = False)[source]#

Bases: CallbackContainer

Federate version, encapsulates xgboostCallbackContainer. .. attribute:: callbacks

list of training callback functions

metric#

eval function callable

is_cv#

whether to do cross validation

Attributes:

EvalsLog(*args, **kwargs)

alias of Dict[str, Dict[str, Union[List[float], List[Tuple[float, float]]]]]

Methods:

__init__(callbacks[, metric, is_cv])

key(name)

after_iteration(model, epoch, dtrain, evals)

A function to call after training iterations.

EvalsLog(*args, **kwargs)#

alias of Dict[str, Dict[str, Union[List[float], List[Tuple[float, float]]]]]

__init__(callbacks: List[TrainingCallback], metric: Optional[Callable] = None, is_cv: bool = False)[source]#
key(name: str) str[source]#
after_iteration(model, epoch, dtrain, evals) bool[source]#

A function to call after training iterations. :param model: xgboost booster object, which stores training parameters and states :param epoch: number of iteration rounds :param dtrain: DMatrix xgboost format training data :param evals: List[(DMatrix, string)] List of data to evaluate

Returns

Whether the training should be terminated, if the callbacks are successfully executed, return true (eg: EarlyStop returns True, the training is terminated early)

Return type

ret

history: Dict[str, Dict[str, Union[List[float], List[Tuple[float, float]]]]]#

secretflow.ml.boost.homo_boost.boost_core.core module#

Classes:

FedBooster([params, cache, model_file])

Federated Booster internal Internal implementation, it is not recommended for users to call directly! ! !

class secretflow.ml.boost.homo_boost.boost_core.core.FedBooster(params: Optional[Dict] = None, cache: List = (), model_file: Optional[Union[str, PathLike, Booster, bytearray]] = None)[source]#

Bases: Booster

Federated Booster internal Internal implementation, it is not recommended for users to call directly! ! !

params#

Parameters for boosters.

cache#

List of cache items.

model_file#

Path to the model file if it’s string or PathLike.

Methods:

__init__([params, cache, model_file])

param params

Parameters for boosters.

federate_update(params, dtrain, hdata, ...)

federated update function, a variant in xgboost update :param params: Training params dict :param dtrain: Training data in dmatrix format :param hdata: Training data in HdataFrame format :param bin_split_points: Global split point :param iter_round: Iteration rounds :param fobj: Custom evaluation function

save_model(fname)

Save the model to a file.

__init__(params: Optional[Dict] = None, cache: List = (), model_file: Optional[Union[str, PathLike, Booster, bytearray]] = None)[source]#
Parameters
  • params (dict) – Parameters for boosters.

  • cache (list) – List of cache items.

  • model_file (string/os.PathLike/Booster/bytearray) – Path to the model file if it’s string or PathLike.

federate_update(params: Dict, dtrain: DMatrix, hdata: HDataFrame, bin_split_points: List, iter_round: Optional[int] = None, fobj: Optional[Callable] = None)[source]#

federated update function, a variant in xgboost update :param params: Training params dict :param dtrain: Training data in dmatrix format :param hdata: Training data in HdataFrame format :param bin_split_points: Global split point :param iter_round: Iteration rounds :param fobj: Custom evaluation function

save_model(fname: Union[str, PathLike])[source]#

Save the model to a file.

fname#

string or os.PathLike, model path, if the suffix is json, store the model in json format

secretflow.ml.boost.homo_boost.boost_core.training module#

Training Library containing training routines.

Functions:

train(params, dtrain, hdata, bin_split_points)

Specifies the parameter training level federated version of xgboost.

secretflow.ml.boost.homo_boost.boost_core.training.train(params: Dict, dtrain: DMatrix, hdata: HDataFrame, bin_split_points: List, num_boost_round: int = 10, evals: List = (), obj: Optional[Callable] = None, feval: Optional[Callable] = None, maximize: Optional[bool] = None, early_stopping_rounds: Optional[int] = None, evals_result: Optional[Dict] = None, verbose_eval: Union[bool, int] = True, xgb_model: Optional[Union[str, PathLike, Booster, bytearray]] = None, callbacks: Optional[List] = None)[source]#

Specifies the parameter training level federated version of xgboost.

Parameters
  • params – Booster parameters. Reference: https://xgboost.readthedocs.io/en/latest/parameter.html

  • dtrain – The training data passed in in DMatrix format.

  • hdata – The training data passed in in HDataFrame format, the content is consistent with dtrain

  • bin_split_points – The global equal-frequency binning of each feature is recorded

  • num_boost_round – Number of iteration rounds.

  • evals – A list of validation sets to evaluate during training to help us monitor training effects during training.

  • obj – custom objective function.

  • feval – Custom eval function.

  • maximize – Whether the function in feval is optimized in the maximize direction.

  • early_stopping_rounds – used to activate the early_stop strategy, the eval metric of the validation set needs to be executed every early stop round Raised at least once. Correspondingly, at least one item must be added to evals. If there are multiple items in eval metric, then the last item The indicator will be used for early stop strategy

  • evals_result – The evals_result dictionary, used to store the evaluation (eval) results of all items in the watch list.

  • verbose_eval – If verbose_eval is True, the evaluation metrics on the validation set will be printed out at each iteration, and if verbose_eval is true If it is an int, the evaluation metric of the validation set will be printed after each verbose_eval* iterations

  • xgb_model – The trained xgb model can transfer the path or the loaded model for relay training or breakpoint retraining

  • callbacks – a list of callback functions that will be applied to each iteration of training

Returns

a trained booster model

Return type

Booster

Module contents#