Flower 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. Federated learning is conducted using the FedAvg strategy for 5 rounds.
This example uses Flower Datasets to download, partition and preprocess the dataset.
Set up the project#
Clone the project#
Start by cloning the example project:
git clone --depth=1 https://github.com/adap/flower.git && mv flower/examples/fl-tabular . && rm -rf flower && cd 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#
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#
[!NOTE] An update to this example will show how to run this Flower application with the Deployment Engine and TLS certificates, or with Docker.