Skip to content

Commit

Permalink
fixed line len for viewing on GH, removed warnings (Trusted-AI#70)
Browse files Browse the repository at this point in the history
* shortened lines that wrapped awkwardly when viewed on GitHub in tutorial_credit_scoring.ipynb
* got rid of unnecessary warnings in demo_optim_preproc_adult.ipynb and tutorial_credit_scoring.ipynb
  • Loading branch information
hoffmansc authored and animeshsingh committed Apr 27, 2019
1 parent 101bdc0 commit 0cf736f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 30 deletions.
7 changes: 4 additions & 3 deletions aif360/datasets/binary_label_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def validate_dataset(self):
ValueError: `favorable_label` and `unfavorable_label` must be the
only values present in `labels`.
"""
# fix scores before validating
if np.all(self.scores == self.labels):
self.scores = np.float64(self.scores == self.favorable_label)

super(BinaryLabelDataset, self).validate_dataset()

# =========================== SHAPE CHECKING ===========================
Expand All @@ -47,6 +51,3 @@ def validate_dataset(self):
set([self.favorable_label, self.unfavorable_label])):
raise ValueError("The favorable and unfavorable labels provided do "
"not match the labels in the dataset.")

if np.all(self.scores == self.labels):
self.scores = (self.scores == self.favorable_label).astype(np.float64)
11 changes: 1 addition & 10 deletions examples/demo_optim_preproc_adult.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:Privileged and unprivileged groups specified will not be used. The protected attributes are directly specified in data preprocessing function. The current implementation automatically adjusts for discrimination across all groups. This can be changed by changing the optimization code.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand All @@ -194,9 +187,7 @@
" \"dlist\": [.1, 0.05, 0]\n",
"}\n",
" \n",
"OP = OptimPreproc(OptTools, optim_options,\n",
" unprivileged_groups = unprivileged_groups,\n",
" privileged_groups = privileged_groups)\n",
"OP = OptimPreproc(OptTools, optim_options)\n",
"\n",
"OP = OP.fit(dataset_orig_train)\n",
"dataset_transf_train = OP.transform(dataset_orig_train, transform_Y=True)\n",
Expand Down
26 changes: 9 additions & 17 deletions examples/tutorial_credit_scoring.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Load all necessary packages\n",
Expand Down Expand Up @@ -87,21 +85,15 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:'scores' has no well-defined meaning out of range [0, 1].\n"
]
}
],
"outputs": [],
"source": [
"dataset_orig = GermanDataset(protected_attribute_names=['age'], # this dataset also contains protected\n",
" # attribute for \"sex\" which we do not\n",
" # consider in this evaluation\n",
" privileged_classes=[lambda x: x >= 25], # age >=25 is considered privileged\n",
" features_to_drop=['personal_status', 'sex']) # ignore sex-related attributes\n",
"dataset_orig = GermanDataset(\n",
" protected_attribute_names=['age'], # this dataset also contains protected\n",
" # attribute for \"sex\" which we do not\n",
" # consider in this evaluation\n",
" privileged_classes=[lambda x: x >= 25], # age >=25 is considered privileged\n",
" features_to_drop=['personal_status', 'sex'] # ignore sex-related attributes\n",
")\n",
"\n",
"dataset_orig_train, dataset_orig_test = dataset_orig.split([0.7], shuffle=True)\n",
"\n",
Expand Down

0 comments on commit 0cf736f

Please sign in to comment.