aif360.datasets
.CompasDataset
- class aif360.datasets.CompasDataset(label_name='two_year_recid', favorable_classes=[0], protected_attribute_names=['sex', 'race'], privileged_classes=[['Female'], ['Caucasian']], instance_weights_name=None, categorical_features=['age_cat', 'c_charge_degree', 'c_charge_desc'], features_to_keep=['sex', 'age', 'age_cat', 'race', 'juv_fel_count', 'juv_misd_count', 'juv_other_count', 'priors_count', 'c_charge_degree', 'c_charge_desc', 'two_year_recid'], features_to_drop=[], na_values=[], custom_preprocessing=<function default_preprocessing>, metadata={'label_maps': [{0.0: 'No recid.', 1.0: 'Did recid.'}], 'protected_attribute_maps': [{0.0: 'Male', 1.0: 'Female'}, {0.0: 'Not Caucasian', 1.0: 'Caucasian'}]})[source]
ProPublica COMPAS Dataset.
See
aif360/data/raw/compas/README.md
.See
StandardDataset
for a description of the arguments.Note: The label value 0 in this case is considered favorable (no recidivism).
Examples
In some cases, it may be useful to keep track of a mapping from
float -> str
for protected attributes and/or labels. If our use case differs from the default, we can modify the mapping stored inmetadata
:>>> label_map = {1.0: 'Did recid.', 0.0: 'No recid.'} >>> protected_attribute_maps = [{1.0: 'Male', 0.0: 'Female'}] >>> cd = CompasDataset(protected_attribute_names=['sex'], ... privileged_classes=[['Male']], metadata={'label_map': label_map, ... 'protected_attribute_maps': protected_attribute_maps})
Now this information will stay attached to the dataset and can be used for more descriptive visualizations.
Methods
align_datasets
Align the other dataset features, labels and protected_attributes to this dataset.
convert_to_dataframe
Convert the StructuredDataset to a
pandas.DataFrame
.copy
Convenience method to return a copy of this dataset.
export_dataset
Export the dataset and supporting attributes TODO: The preferred file format is HDF
import_dataset
Import the dataset and supporting attributes TODO: The preferred file format is HDF
split
Split this dataset into multiple partitions.
subset
Subset of dataset based on position :param indexes: iterable which contains row indexes
temporarily_ignore
Temporarily add the fields provided to
ignore_fields
.validate_dataset
Error checking and type validation.
- __init__(label_name='two_year_recid', favorable_classes=[0], protected_attribute_names=['sex', 'race'], privileged_classes=[['Female'], ['Caucasian']], instance_weights_name=None, categorical_features=['age_cat', 'c_charge_degree', 'c_charge_desc'], features_to_keep=['sex', 'age', 'age_cat', 'race', 'juv_fel_count', 'juv_misd_count', 'juv_other_count', 'priors_count', 'c_charge_degree', 'c_charge_desc', 'two_year_recid'], features_to_drop=[], na_values=[], custom_preprocessing=<function default_preprocessing>, metadata={'label_maps': [{0.0: 'No recid.', 1.0: 'Did recid.'}], 'protected_attribute_maps': [{0.0: 'Male', 1.0: 'Female'}, {0.0: 'Not Caucasian', 1.0: 'Caucasian'}]})[source]
See
StandardDataset
for a description of the arguments.Note: The label value 0 in this case is considered favorable (no recidivism).
Examples
In some cases, it may be useful to keep track of a mapping from
float -> str
for protected attributes and/or labels. If our use case differs from the default, we can modify the mapping stored inmetadata
:>>> label_map = {1.0: 'Did recid.', 0.0: 'No recid.'} >>> protected_attribute_maps = [{1.0: 'Male', 0.0: 'Female'}] >>> cd = CompasDataset(protected_attribute_names=['sex'], ... privileged_classes=[['Male']], metadata={'label_map': label_map, ... 'protected_attribute_maps': protected_attribute_maps})
Now this information will stay attached to the dataset and can be used for more descriptive visualizations.