Collection
The Collection
classes provide a way to organize and iterate through groups of related fairness scenarios, making it easier to run batch analyses across multiple datasets with different sensitive attribute configurations.
Class Documentation
fairml_datasets.collection.Collection
A collection of fairness scenarios that can be iterated through.
This class provides a way to group multiple related scenarios and perform batch operations or analyses across them.
Source code in fairml_datasets/collection.py
Functions
__init__(scenarios)
Initialize a Collection with a list of scenarios.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scenarios
|
List[Scenario]
|
List of Scenario objects |
required |
__iter__()
Make the Collection iterable, yielding each scenario in turn.
Returns:
Type | Description |
---|---|
Iterator over scenarios in the collection |
fairml_datasets.collection.PrespecifiedCollection
Bases: Collection
A collection of scenarios with predefined dataset and sensitive column configurations.
This class derives from Collection and is designed to be subclassed with a specific 'info' attribute that defines which datasets and sensitive columns to use.
Source code in fairml_datasets/collection.py
Functions
__init__()
Initialize a PrespecifiedCollection based on the predefined scenario ids.
Source code in fairml_datasets/collection.py
Usage Examples
Basic Usage
from fairml_datasets.scenario import Scenario
from fairml_datasets.collection import Collection
# Create scenarios
scenario1 = Scenario("adult", ["sex"])
scenario2 = Scenario("compas", ["race"])
# Create a collection
collection = Collection([scenario1, scenario2])
# Iterate through scenarios
for scenario in collection:
print(f"Dataset: {scenario.dataset_id}, Sensitive columns: {scenario.sensitive_columns}")
df = scenario.load(stage="prepared")