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:
ExecutorClient-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 slicesX_train/X_valto the selected features. Idempotent: if the same mask is received a second time (e.g. due to task retransmission) the call returnsOKimmediately 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_nameonFeatureElectionController.
Note
Call
set_data()before the executor is registered with the FL runtime.FeatureElectionExecutorhas noclient_idattribute; usefl_ctx.get_identity_name()inside_load_data_if_neededto 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. WhenNonea fresh scaler is fitted onX_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.