# NOT RUN {
# Example with Adult Dataset
load_aif360_lib()
ad <- adult_dataset()
p <- list("race",1)
u <- list("race", 0)
col_names <- c(ad$feature_names, "label")
ad_df <- data.frame(ad$features, ad$labels)
colnames(ad_df) <- col_names
lr <- glm(label ~ ., data=ad_df, family=binomial)
ad_prob <- predict(lr, ad_df)
ad_pred <- factor(ifelse(ad_prob> 0.5,1,0))
ad_df_pred <- data.frame(ad_df)
ad_df_pred$label <- as.character(ad_pred)
colnames(ad_df_pred) <- c(ad$feature_names, 'label')
ad_ds <- aif_dataset(ad_df, target_column='label', favor_label = 1,
unfavor_label = 0, unprivileged_protected_attribute = 0,
privileged_protected_attribute = 1, protected_attribute='race')
ad_ds_pred <- aif_dataset(ad_df_pred, target_column='label', favor_label = 1,
unfavor_label = 0, unprivileged_protected_attribute = 0,
privileged_protected_attribute = 1, protected_attribute='race')
roc <- reject_option_classification(unprivileged_groups = u,
privileged_groups = p,
low_class_thresh = 0.01,
high_class_thresh = 0.99,
num_class_thresh = as.integer(100),
num_ROC_margin = as.integer(50),
metric_name = "Statistical parity difference",
metric_ub = 0.05,
metric_lb = -0.05)
roc <- roc$fit(ad_ds, ad_ds_pred)
ds_transformed_pred <- roc$predict(ad_ds_pred)
# }
Run the code above in your browser using DataLab