nvflare.app_opt.xgboost.recipes package

Submodules

Module contents

class XGBBaggingRecipe(name: str, min_clients: int, num_rounds: int = 1, num_client_bagging: int | None = None, num_local_parallel_tree: int = 5, local_subsample: float = 0.8, learning_rate: float = 0.1, objective: str = 'binary:logistic', max_depth: int = 8, eval_metric: str = 'auc', tree_method: str = 'hist', use_gpus: bool = False, nthread: int = 16, lr_mode: str = 'uniform', save_name: str = 'xgboost_model.json', data_loader_id: str = 'dataloader')[source]

Bases: Recipe

XGBoost Tree-Based Bagging Recipe for federated Random Forest.

This recipe implements federated Random Forest using XGBoost’s tree-based bagging approach. Each client trains a local sub-forest on their data, and these sub-forests are aggregated on the server to form the global model.

Parameters:
  • name (str) – Name of the federated job.

  • min_clients (int) – The minimum number of clients for the job.

  • num_rounds (int, optional) – Number of training rounds. Default is 1 (standard for Random Forest).

  • num_client_bagging (int, optional) – Number of clients for bagging. Default is min_clients.

  • num_local_parallel_tree (int, optional) – Number of parallel trees per client. Default is 5.

  • local_subsample (float, optional) – Subsample ratio for local training. Default is 0.8.

  • learning_rate (float, optional) – Learning rate for XGBoost. Default is 0.1.

  • objective (str, optional) – Learning objective. Default is “binary:logistic”.

  • max_depth (int, optional) – Maximum tree depth. Default is 8.

  • eval_metric (str, optional) – Evaluation metric. Default is “auc”.

  • tree_method (str, optional) – Tree construction method. Default is “hist”.

  • use_gpus (bool, optional) – Whether to use GPUs. Default is False.

  • nthread (int, optional) – Number of threads. Default is 16.

  • lr_mode (str, optional) – Learning rate mode (“uniform” or “scaled”). Default is “uniform”.

  • save_name (str, optional) – Model save name. Default is “xgboost_model.json”.

  • data_loader_id (str, optional) – ID of the data loader component. Default is “dataloader”.

Example

from nvflare.app_opt.xgboost.recipes import XGBBaggingRecipe
from nvflare.recipe import SimEnv

recipe = XGBBaggingRecipe(
    name="random_forest",
    min_clients=5,
    num_rounds=1,
    num_local_parallel_tree=5,
    local_subsample=0.5,
)

env = SimEnv(num_clients=5)
run = recipe.execute(env)

This is base class of a recipe. Recipes are implemented by jobs. A concrete recipe must provide the job for recipe implementation.

Parameters:

job – the job that implements the recipe.

add_to_client(site_name: str, dataloader, lr_scale: float = 1.0)[source]

Add executor and dataloader to a specific client site.

Parameters:
  • site_name – Name of the client site (e.g., “site-1”)

  • dataloader – XGBDataLoader instance for this client

  • lr_scale – Learning rate scale factor for this client (default: 1.0)

configure()[source]

Configure the federated job for XGBoost bagging.