nvflare.app_opt.feature_election.executor module

class FeatureElectionExecutor(fs_method: str = 'lasso', fs_params: Dict | None = None, eval_metric: str = 'f1', task_name: str = 'feature_election')[source]

Bases: Executor

Client-side executor for the Feature Election federated workflow.

Handles four request types dispatched by FeatureElectionController:

  • feature_selection — runs the configured FS method on local data and returns a boolean feature mask and per-feature scores.

  • tuning_eval — evaluates a candidate mask proposed by the controller during the hill-climbing phase and returns the local score.

  • apply_mask — permanently slices X_train / X_val to the selected features. Idempotent: if the same mask is received a second time (e.g. due to task retransmission) the call returns OK immediately without modifying data.

  • train — performs one FedAvg round on the masked feature set and returns the updated model weights.

Parameters:
  • fs_method – Feature selection algorithm. One of 'lasso', 'elastic_net', 'mutual_info', 'random_forest', 'pyimpetus'.

  • fs_params – Extra keyword arguments forwarded to the FS algorithm.

  • eval_metric'f1' (weighted) or 'accuracy', used for tuning eval and local scoring.

  • task_name – Must match the task_name on FeatureElectionController.

Note

Call set_data() before the executor is registered with the FL runtime. FeatureElectionExecutor has no client_id attribute; use fl_ctx.get_identity_name() inside _load_data_if_needed to retrieve the site name assigned by the FL platform.

Init FLComponent.

The FLComponent is the base class of all FL Components. (executors, controllers, responders, filters, aggregators, and widgets are all FLComponents)

FLComponents have the capability to handle and fire events and contain various methods for logging.

evaluate_model(X_train, y_train, X_val, y_val, scaler=None) float[source]

Helper method to train and evaluate a model locally. Required for the ‘simulate_election’ functionality and tests.

Parameters:

scaler – Optional pre-fitted StandardScaler. When provided the data is transformed (not fit-transformed), ensuring the same normalisation parameters are used as those established on the same feature set by the caller. When None a fresh scaler is fitted on X_train.

execute(task_name: str, shareable: Shareable, fl_ctx: FLContext, abort_signal: Signal) Shareable[source]

Executes a task.

Parameters:
  • task_name (str) – task name.

  • shareable (Shareable) – input shareable.

  • fl_ctx (FLContext) – fl context.

  • abort_signal (Signal) – signal to check during execution to determine whether this task is aborted.

Returns:

An output shareable.

perform_feature_selection() Tuple[ndarray, ndarray][source]
set_data(X_train, y_train, X_val=None, y_val=None, feature_names=None)[source]

Set data for the executor. X_val and y_val are optional; if not provided, training data is used for evaluation.