IidPartitioner#
- class IidPartitioner(num_partitions: int)[source]#
Bases:
Partitioner
Partitioner creates each partition sampled randomly from the dataset.
- Parameters:
num_partitions (int) – The total number of partitions that the data will be divided into.
Examples
>>> from flwr_datasets import FederatedDataset >>> from flwr_datasets.partitioner import IidPartitioner >>> >>> partitioner = IidPartitioner(num_partitions=10) >>> fds = FederatedDataset(dataset="mnist", partitioners={"train": partitioner}) >>> partition = fds.load_partition(0)
Methods
Check if a dataset has been assigned to the partitioner.
load_partition
(partition_id)Load a single IID partition based on the partition index.
Attributes
Dataset property.
Total number of partitions.
- property dataset: Dataset#
Dataset property.
- is_dataset_assigned() bool #
Check if a dataset has been assigned to the partitioner.
This method returns True if a dataset is already set for the partitioner, otherwise, it returns False.
- Returns:
dataset_assigned – True if a dataset is assigned, otherwise False.
- Return type:
bool
- load_partition(partition_id: int) Dataset [source]#
Load a single IID partition based on the partition index.
- Parameters:
partition_id (int) – the index that corresponds to the requested partition
- Returns:
dataset_partition – single dataset partition
- Return type:
Dataset
- property num_partitions: int#
Total number of partitions.