@flwrlabs/fl-tabular
flwr new @flwrlabs/fl-tabularFlower Example on Adult Census Income Tabular Dataset
This code exemplifies a federated learning setup using the Flower framework on the "Adult Census Income" tabular dataset. The "Adult Census Income" dataset contains demographic information such as age, education, occupation, etc., with the target attribute being income level (<=50K or >50K). The dataset is partitioned into subsets, simulating a federated environment with 5 clients, each holding a distinct portion of the data. Categorical variables are one-hot encoded, and the data is split into training and testing sets. A simple deep neural network is used for this task, and federated learning is performed using the FedAvg strategy over 5 rounds.
This example uses Flower Datasets to download, partition and preprocess the dataset.
Set up the project
Fetch the app
Install Flower:
pip install flwr
Fetch the app:
flwr new @flwrlabs/fl-tabular
This will create a new directory called fl-tabular containing the following files:
fl-tabular ├── fltabular │ ├── client_app.py # Defines your ClientApp │ ├── server_app.py # Defines your ServerApp │ └── task.py # Defines your model, training and data loading ├── pyproject.toml # Project metadata like dependencies and configs └── README.md
Install dependencies and project
Install the dependencies defined in pyproject.toml as well as the fltabular package.
# From a new python environment, run: pip install -e .
Run the Example
You can run your ClientApp and ServerApp in both simulation and deployment mode without making changes to the code. If you are starting with Flower, we recommend you using the simulation model as it requires fewer components to be launched manually. By default, flwr run will make use of the Simulation Engine.
Run with the Simulation Engine
NOTE
Check the Simulation Engine documentation to learn more about Flower simulations and how to optimize them.
This example is designed to run with five virtual clients. Let's first locate the Flower Configuration file and edit one of the existing connections to make it use five nodes.
Locate the Flower Configuration file:
flwr config list
# Example output: Flower Config file: /path/to/your/.flwr/config.toml SuperLink connections: supergrid local (default)
Modify the local connection so it has five supernodes:
[superlink.local] options.num-supernodes = 5
Finally, let's run the app:
flwr run .
You can also override some of the settings for your ClientApp and ServerApp defined in pyproject.toml. For example:
flwr run . --run-config num-server-rounds=10
Run with the Deployment Engine
Follow this how-to guide to run the same app in this example but with Flower's Deployment Engine. After that, you might be intersted in setting up secure TLS-enabled communications and SuperNode authentication in your federation.
If you are already familiar with how the Deployment Engine works, you may want to learn how to run it using Docker. Check out the Flower with Docker documentation.