{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fairness and Explainability with SageMaker Clarify"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook. \n",
"\n",
"\n",
"\n",
"---"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Runtime\n",
"\n",
"This notebook takes approximately 30 minutes to run.\n",
"\n",
"## Contents\n",
"\n",
"1. [Overview](#Overview)\n",
"1. [Prerequisites and Data](#Prerequisites-and-Data)\n",
" 1. [Import Libraries](#Import-Libraries)\n",
" 1. [Set Configurations](#Set-Configurations)\n",
" 1. [Download data](#Download-data)\n",
" 1. [Loading the data: Adult Dataset](#Loading-the-data:-Adult-Dataset) \n",
" 1. [Data inspection](#Data-inspection) \n",
" 1. [Encode and Upload the Dataset](#Encode-and-Upload-the-Dataset) \n",
"1. [Train and Deploy XGBoost Model](#Train-XGBoost-Model)\n",
" 1. [Train Model](#Train-Model)\n",
" 1. [Create Model](#Create-Model)\n",
"1. [Amazon SageMaker Clarify](#Amazon-SageMaker-Clarify)\n",
" 1. [Detecting Bias](#Detecting-Bias)\n",
" 1. [Writing DataConfig](#Writing-DataConfig)\n",
" 1. [Writing ModelConfig](#Writing-ModelConfig)\n",
" 1. [Writing ModelPredictedLabelConfig](#Writing-ModelPredictedLabelConfig)\n",
" 1. [Writing BiasConfig](#Writing-BiasConfig)\n",
" 1. [Pre-training Bias](#Pre-training-Bias)\n",
" 1. [Post-training Bias](#Post-training-Bias)\n",
" 1. [Viewing the Bias Report](#Viewing-the-Bias-Report)\n",
" 1. [Explaining Predictions](#Explaining-Predictions)\n",
" 1. [Viewing the Explainability Report](#Viewing-the-Explainability-Report)\n",
" 1. [Analysis of local explanations](#Analysis-of-local-explanations)\n",
"1. [Clean Up](#Clean-Up)\n",
"\n",
"## Overview\n",
"Amazon SageMaker Clarify helps improve your machine learning models by detecting potential bias and helping explain how these models make predictions. The fairness and explainability functionality provided by SageMaker Clarify takes a step towards enabling AWS customers to build trustworthy and understandable machine learning models. The product comes with the tools to help you with the following tasks.\n",
"\n",
"* Measure biases that can occur during each stage of the ML lifecycle (data collection, model training and tuning, and monitoring of ML models deployed for inference).\n",
"* Generate model governance reports targeting risk and compliance teams and external regulators.\n",
"* Provide explanations of the data, models, and monitoring used to assess predictions.\n",
"\n",
"This sample notebook walks you through: \n",
"1. Key terms and concepts needed to understand SageMaker Clarify\n",
"1. Measuring the pre-training bias of a dataset and post-training bias of a model\n",
"1. Explaining the importance of the various input features on the model's decision\n",
"1. Accessing the reports through SageMaker Studio if you have an instance set up.\n",
"\n",
"In doing so, the notebook first trains a [SageMaker XGBoost](https://docs.aws.amazon.com/sagemaker/latest/dg/xgboost.html) model using training dataset, then use [Amazon SageMaker Python SDK](https://sagemaker.readthedocs.io/en/stable/) to launch SageMaker Clarify jobs to analyze an example dataset in CSV format. \n",
"\n",
"SageMaker Clarify also supports analyzing dataset in [SageMaker JSON Lines dense format](https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#common-in-formats), which is illustrated in [another notebook](https://github.com/aws/amazon-sagemaker-examples/blob/master/sagemaker_processing/fairness_and_explainability/fairness_and_explainability_jsonlines_format.ipynb). Additionally, there is a [peer example available](https://github.com/aws/amazon-sagemaker-examples/blob/main/sagemaker-clarify/fairness_and_explainability/fairness_and_explainability_boto3.ipynb) that utilizes the [AWS SDK for Python](https://aws.amazon.com/sdk-for-python/) to launch SageMaker Clarify jobs to analyze data in CSV format. "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prerequisites and Data\n",
"### Import Libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import os\n",
"import boto3\n",
"from datetime import datetime\n",
"from sagemaker import get_execution_role, session"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Set Configurations"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Region: ap-south-1\n",
"Role: arn:aws:iam::000000000000:role/service-role/SMClarifySageMaker-ExecutionRole\n"
]
}
],
"source": [
"# Initialize sagemaker session\n",
"sagemaker_session = session.Session()\n",
"\n",
"region = sagemaker_session.boto_region_name\n",
"print(f\"Region: {region}\")\n",
"\n",
"role = get_execution_role()\n",
"print(f\"Role: {role}\")\n",
"\n",
"bucket = sagemaker_session.default_bucket()\n",
"\n",
"prefix = \"sagemaker/DEMO-sagemaker-clarify\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Download data\n",
"Data Source: [https://archive.ics.uci.edu/ml/machine-learning-databases/adult/](https://archive.ics.uci.edu/ml/machine-learning-databases/adult/)\n",
"\n",
"Let's __download__ the data and save it in the local folder with the name adult.data and adult.test from UCI repository$^{[2]}$.\n",
"\n",
"$^{[2]}$Dua Dheeru, and Efi Karra Taniskidou. \"[UCI Machine Learning Repository](http://archive.ics.uci.edu/ml)\". Irvine, CA: University of California, School of Information and Computer Science (2017)."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"adult.data already on disk.\n",
"adult.test already on disk.\n"
]
}
],
"source": [
"from sagemaker.s3 import S3Downloader\n",
"\n",
"adult_columns = [\n",
" \"Age\",\n",
" \"Workclass\",\n",
" \"fnlwgt\",\n",
" \"Education\",\n",
" \"Education-Num\",\n",
" \"Marital Status\",\n",
" \"Occupation\",\n",
" \"Relationship\",\n",
" \"Ethnic group\",\n",
" \"Sex\",\n",
" \"Capital Gain\",\n",
" \"Capital Loss\",\n",
" \"Hours per week\",\n",
" \"Country\",\n",
" \"Target\",\n",
"]\n",
"if not os.path.isfile(\"adult.data\"):\n",
" S3Downloader.download(\n",
" s3_uri=\"s3://{}/{}\".format(\n",
" f\"sagemaker-example-files-prod-{region}\", \"datasets/tabular/uci_adult/adult.data\"\n",
" ),\n",
" local_path=\"./\",\n",
" sagemaker_session=sagemaker_session,\n",
" )\n",
" print(\"adult.data saved!\")\n",
"else:\n",
" print(\"adult.data already on disk.\")\n",
"\n",
"if not os.path.isfile(\"adult.test\"):\n",
" S3Downloader.download(\n",
" s3_uri=\"s3://{}/{}\".format(\n",
" f\"sagemaker-example-files-prod-{region}\", \"datasets/tabular/uci_adult/adult.test\"\n",
" ),\n",
" local_path=\"./\",\n",
" sagemaker_session=sagemaker_session,\n",
" )\n",
" print(\"adult.test saved!\")\n",
"else:\n",
" print(\"adult.test already on disk.\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Loading the data: Adult Dataset\n",
"From the UCI repository of machine learning datasets, this database contains 14 features concerning demographic characteristics of 45,222 rows (32,561 for training and 12,661 for testing). The task is to predict whether a person has a yearly income that is more or less than $50,000.\n",
"\n",
"Here are the features and their possible values:\n",
"\n",
"1. **Age**: continuous.\n",
"1. **Workclass**: Private, Self-emp-not-inc, Self-emp-inc, Federal-gov, Local-gov, State-gov, Without-pay, Never-worked.\n",
"1. **Fnlwgt**: continuous (the number of people the census takers believe that observation represents).\n",
"1. **Education**: Bachelors, Some-college, 11th, HS-grad, Prof-school, Assoc-acdm, Assoc-voc, 9th, 7th-8th, 12th, Masters, 1st-4th, 10th, Doctorate, 5th-6th, Preschool.\n",
"1. **Education-num**: continuous.\n",
"1. **Marital-status**: Married-civ-spouse, Divorced, Never-married, Separated, Widowed, Married-spouse-absent, Married-AF-spouse.\n",
"1. **Occupation**: Tech-support, Craft-repair, Other-service, Sales, Exec-managerial, Prof-specialty, Handlers-cleaners, Machine-op-inspct, Adm-clerical, Farming-fishing, Transport-moving, Priv-house-serv, Protective-serv, Armed-Forces.\n",
"1. **Relationship**: Wife, Own-child, Husband, Not-in-family, Other-relative, Unmarried.\n",
"1. **Ethnic group**: White, Asian-Pac-Islander, Amer-Indian-Eskimo, Other, Black.\n",
"1. **Sex**: Female, Male.\n",
" * **Note**: this data is extracted from the 1994 Census and enforces a binary option on Sex\n",
"1. **Capital-gain**: continuous.\n",
"1. **Capital-loss**: continuous.\n",
"1. **Hours-per-week**: continuous.\n",
"1. **Native-country**: United-States, Cambodia, England, Puerto-Rico, Canada, Germany, Outlying-US(Guam-USVI-etc), India, Japan, Greece, South, China, Cuba, Iran, Honduras, Philippines, Italy, Poland, Jamaica, Vietnam, Mexico, Portugal, Ireland, France, Dominican-Republic, Laos, Ecuador, Taiwan, Haiti, Columbia, Hungary, Guatemala, Nicaragua, Scotland, Thailand, Yugoslavia, El-Salvador, Trinadad&Tobago, Peru, Hong, Holand-Netherlands.\n",
"\n",
"Next, we specify our binary prediction task: \n",
"\n",
"15. **Target**: <=50,000, >$50,000."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
Age
\n",
"
Workclass
\n",
"
fnlwgt
\n",
"
Education
\n",
"
Education-Num
\n",
"
Marital Status
\n",
"
Occupation
\n",
"
Relationship
\n",
"
Ethnic group
\n",
"
Sex
\n",
"
Capital Gain
\n",
"
Capital Loss
\n",
"
Hours per week
\n",
"
Country
\n",
"
Target
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
39
\n",
"
State-gov
\n",
"
77516
\n",
"
Bachelors
\n",
"
13
\n",
"
Never-married
\n",
"
Adm-clerical
\n",
"
Not-in-family
\n",
"
White
\n",
"
Male
\n",
"
2174
\n",
"
0
\n",
"
40
\n",
"
United-States
\n",
"
<=50K
\n",
"
\n",
"
\n",
"
1
\n",
"
50
\n",
"
Self-emp-not-inc
\n",
"
83311
\n",
"
Bachelors
\n",
"
13
\n",
"
Married-civ-spouse
\n",
"
Exec-managerial
\n",
"
Husband
\n",
"
White
\n",
"
Male
\n",
"
0
\n",
"
0
\n",
"
13
\n",
"
United-States
\n",
"
<=50K
\n",
"
\n",
"
\n",
"
2
\n",
"
38
\n",
"
Private
\n",
"
215646
\n",
"
HS-grad
\n",
"
9
\n",
"
Divorced
\n",
"
Handlers-cleaners
\n",
"
Not-in-family
\n",
"
White
\n",
"
Male
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
United-States
\n",
"
<=50K
\n",
"
\n",
"
\n",
"
3
\n",
"
53
\n",
"
Private
\n",
"
234721
\n",
"
11th
\n",
"
7
\n",
"
Married-civ-spouse
\n",
"
Handlers-cleaners
\n",
"
Husband
\n",
"
Black
\n",
"
Male
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
United-States
\n",
"
<=50K
\n",
"
\n",
"
\n",
"
4
\n",
"
28
\n",
"
Private
\n",
"
338409
\n",
"
Bachelors
\n",
"
13
\n",
"
Married-civ-spouse
\n",
"
Prof-specialty
\n",
"
Wife
\n",
"
Black
\n",
"
Female
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
Cuba
\n",
"
<=50K
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Age Workclass fnlwgt Education Education-Num \\\n",
"0 39 State-gov 77516 Bachelors 13 \n",
"1 50 Self-emp-not-inc 83311 Bachelors 13 \n",
"2 38 Private 215646 HS-grad 9 \n",
"3 53 Private 234721 11th 7 \n",
"4 28 Private 338409 Bachelors 13 \n",
"\n",
" Marital Status Occupation Relationship Ethnic group Sex \\\n",
"0 Never-married Adm-clerical Not-in-family White Male \n",
"1 Married-civ-spouse Exec-managerial Husband White Male \n",
"2 Divorced Handlers-cleaners Not-in-family White Male \n",
"3 Married-civ-spouse Handlers-cleaners Husband Black Male \n",
"4 Married-civ-spouse Prof-specialty Wife Black Female \n",
"\n",
" Capital Gain Capital Loss Hours per week Country Target \n",
"0 2174 0 40 United-States <=50K \n",
"1 0 0 13 United-States <=50K \n",
"2 0 0 40 United-States <=50K \n",
"3 0 0 40 United-States <=50K \n",
"4 0 0 40 Cuba <=50K "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"training_data = pd.read_csv(\n",
" \"adult.data\", names=adult_columns, sep=r\"\\s*,\\s*\", engine=\"python\", na_values=\"?\"\n",
").dropna()\n",
"\n",
"testing_data = pd.read_csv(\n",
" \"adult.test\", names=adult_columns, sep=r\"\\s*,\\s*\", engine=\"python\", na_values=\"?\", skiprows=1\n",
").dropna()\n",
"\n",
"training_data.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data inspection\n",
"Plotting histograms for the distribution of the different features is a good way to visualize the data. Let's plot a few of the features that can be considered _sensitive_. \n",
"Let's take a look specifically at the Sex feature of a census respondent. In the first plot we see that there are fewer Female respondents as a whole but especially in the positive outcomes, where they form ~$\\frac{1}{7}$th of respondents."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEICAYAAABfz4NwAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAY2UlEQVR4nO3de7RedX3n8fenhCJqoVyONE2iQYm2kKlhJWZQq4uu2BIvFZwBDdMKtKwVZeFYl3ZmQG11tJkRFWmZJdg4MARGuYyIsCpUEarUEcGDRsK1hItyTAYOiBiqRBO/88fzO/pw8uTcc04u79dae539fPfvt/fv4XI+z/7t/ZydqkKSpF+b6QFIknYOBoIkCTAQJEmNgSBJAgwESVJjIEiSAANB2ikkOSTJTUk2JTl7psejPZOBoF1Skv+QpD/JU0k2Jrkuye9Pw3EryWE7YNcrgceA/arqPT2OOzfJlUkeS/JkknVJTtkB49AebNZMD0AaryTvBs4A3g58CfgZsBw4Fvj6DA5tMl4A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FwSpKDWps/b32XAO/sqgOQ5HeBtwCvbGcnW4E/2XFvUbuhy4AVSZ4F/B5wS9e2e4BXV9WRwF8D/61H//cBN1bVy4A/AD6W5Dk7eMy7NaeMdg/PmDJKspDOL/jrk0Dnux0bu9oPfelvHXBnVW1s/R6g843xx+mEwJtau3nAglYfsgxYDHyrHWNf4NEpfVfarVXV7e1614nAtcM27w+sSbKAzp+x2bvHLv4IeGOSv2yvnwU8H7h7x4x492cg7J5C5xf9y7ezfXP7+Yuu9aHXs5IcDbwGeHlV/STJV+n8zzb8GGuq6sypGrT2SNcAHweOBrrPQj8M/FNVvamFxld79A3w76vKP3I5RZwy2j3dC/QleTlAkr2THDGO/vsDT7Qw+B3gqB5tbgCOT/K8dowDk2z3ryhK23Eh8KGqWjesvj+/ush8ynb6fgn4j2mnqEmO3CEj3IMYCLuh9kyJ44GzknwXWAu8Yhy7+Ec6Zwq30/mk9s0ex7gLeD/w5dbuemD2JIeuPUxVDVTV3/XY9FHgvyf5v3SmPHv5MJ2ppNuT3NFeaxL80xWSJMAzBElSYyBIkgADQZLUGAiSJMBAkCQ1BoIkCTAQJEnN/wcqlWaXRFP9cQAAAABJRU5ErkJggg==",
"text/plain": [
"
"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"training_data[\"Sex\"].where(training_data[\"Target\"] == \">50K\").value_counts().sort_values().plot(\n",
" kind=\"bar\", title=\"Counts of Sex earning >$50K\", rot=0\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Encode and Upload the Dataset\n",
"Here we encode the training and test data. Encoding input data is not necessary for SageMaker Clarify, but is necessary for the model."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from sklearn import preprocessing\n",
"\n",
"\n",
"def number_encode_features(df):\n",
" result = df.copy()\n",
" encoders = {}\n",
" for column in result.columns:\n",
" if result.dtypes[column] == np.object:\n",
" encoders[column] = preprocessing.LabelEncoder()\n",
" result[column] = encoders[column].fit_transform(result[column].fillna(\"None\"))\n",
" return result, encoders\n",
"\n",
"\n",
"training_data = pd.concat([training_data[\"Target\"], training_data.drop([\"Target\"], axis=1)], axis=1)\n",
"training_data, _ = number_encode_features(training_data)\n",
"training_data.to_csv(\"train_data.csv\", index=False, header=False)\n",
"\n",
"testing_data, _ = number_encode_features(testing_data)\n",
"test_features = testing_data.drop([\"Target\"], axis=1)\n",
"test_target = testing_data[\"Target\"]\n",
"test_features.to_csv(\"test_features.csv\", index=False, header=False)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"A quick note about our encoding: the \"Female\" Sex value has been encoded as 0 and \"Male\" as 1."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
"
\n",
"
\n",
"
Target
\n",
"
Age
\n",
"
Workclass
\n",
"
fnlwgt
\n",
"
Education
\n",
"
Education-Num
\n",
"
Marital Status
\n",
"
Occupation
\n",
"
Relationship
\n",
"
Ethnic group
\n",
"
Sex
\n",
"
Capital Gain
\n",
"
Capital Loss
\n",
"
Hours per week
\n",
"
Country
\n",
"
\n",
" \n",
" \n",
"
\n",
"
0
\n",
"
0
\n",
"
39
\n",
"
5
\n",
"
77516
\n",
"
9
\n",
"
13
\n",
"
4
\n",
"
0
\n",
"
1
\n",
"
4
\n",
"
1
\n",
"
2174
\n",
"
0
\n",
"
40
\n",
"
38
\n",
"
\n",
"
\n",
"
1
\n",
"
0
\n",
"
50
\n",
"
4
\n",
"
83311
\n",
"
9
\n",
"
13
\n",
"
2
\n",
"
3
\n",
"
0
\n",
"
4
\n",
"
1
\n",
"
0
\n",
"
0
\n",
"
13
\n",
"
38
\n",
"
\n",
"
\n",
"
2
\n",
"
0
\n",
"
38
\n",
"
2
\n",
"
215646
\n",
"
11
\n",
"
9
\n",
"
0
\n",
"
5
\n",
"
1
\n",
"
4
\n",
"
1
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
38
\n",
"
\n",
"
\n",
"
3
\n",
"
0
\n",
"
53
\n",
"
2
\n",
"
234721
\n",
"
1
\n",
"
7
\n",
"
2
\n",
"
5
\n",
"
0
\n",
"
2
\n",
"
1
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
38
\n",
"
\n",
"
\n",
"
4
\n",
"
0
\n",
"
28
\n",
"
2
\n",
"
338409
\n",
"
9
\n",
"
13
\n",
"
2
\n",
"
9
\n",
"
5
\n",
"
2
\n",
"
0
\n",
"
0
\n",
"
0
\n",
"
40
\n",
"
4
\n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Target Age Workclass fnlwgt Education Education-Num Marital Status \\\n",
"0 0 39 5 77516 9 13 4 \n",
"1 0 50 4 83311 9 13 2 \n",
"2 0 38 2 215646 11 9 0 \n",
"3 0 53 2 234721 1 7 2 \n",
"4 0 28 2 338409 9 13 2 \n",
"\n",
" Occupation Relationship Ethnic group Sex Capital Gain Capital Loss \\\n",
"0 0 1 4 1 2174 0 \n",
"1 3 0 4 1 0 0 \n",
"2 5 1 4 1 0 0 \n",
"3 5 0 2 1 0 0 \n",
"4 9 5 2 0 0 0 \n",
"\n",
" Hours per week Country \n",
"0 40 38 \n",
"1 13 38 \n",
"2 40 38 \n",
"3 40 38 \n",
"4 40 4 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"training_data.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Lastly, let's upload the data to S3."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from sagemaker.s3 import S3Uploader\n",
"from sagemaker.inputs import TrainingInput\n",
"\n",
"train_uri = S3Uploader.upload(\"train_data.csv\", \"s3://{}/{}\".format(bucket, prefix))\n",
"train_input = TrainingInput(train_uri, content_type=\"csv\")\n",
"test_uri = S3Uploader.upload(\"test_features.csv\", \"s3://{}/{}\".format(bucket, prefix))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Train XGBoost Model\n",
"#### Train Model\n",
"Since our focus is on understanding how to use SageMaker Clarify, we keep it simple by using a standard XGBoost model.\n",
"\n",
"It takes about 5 minutes for the model to be trained."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:sagemaker:Creating training-job with name: sagemaker-xgboost-2023-02-07-05-54-36-442\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"2023-02-07 05:54:36 Starting - Starting the training job..\n",
"2023-02-07 05:54:50 Starting - Preparing the instances for training........\n",
"2023-02-07 05:55:32 Downloading - Downloading input data....\n",
"2023-02-07 05:55:57 Training - Downloading the training image...\n",
"2023-02-07 05:56:18 Training - Training image download completed. Training in progress.......\n",
"2023-02-07 05:56:53 Uploading - Uploading generated training model.\n",
"2023-02-07 05:57:04 Completed - Training job completed\n"
]
}
],
"source": [
"from sagemaker.image_uris import retrieve\n",
"from sagemaker.estimator import Estimator\n",
"\n",
"# This references the AWS managed XGBoost container\n",
"xgboost_image_uri = retrieve(\"xgboost\", region, version=\"1.5-1\")\n",
"\n",
"xgb = Estimator(\n",
" xgboost_image_uri,\n",
" role,\n",
" instance_count=1,\n",
" instance_type=\"ml.m5.xlarge\",\n",
" disable_profiler=True,\n",
" sagemaker_session=sagemaker_session,\n",
")\n",
"\n",
"xgb.set_hyperparameters(\n",
" max_depth=5,\n",
" eta=0.2,\n",
" gamma=4,\n",
" min_child_weight=6,\n",
" subsample=0.8,\n",
" objective=\"binary:logistic\",\n",
" num_round=800,\n",
")\n",
"\n",
"xgb.fit({\"train\": train_input}, logs=False)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create Model\n",
"Here we create the SageMaker model."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:sagemaker:Creating model with name: DEMO-clarify-model-07-02-2023-05-57-08\n"
]
},
{
"data": {
"text/plain": [
"'DEMO-clarify-model-07-02-2023-05-57-08'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model_name = \"DEMO-clarify-model-{}\".format(datetime.now().strftime(\"%d-%m-%Y-%H-%M-%S\"))\n",
"model = xgb.create_model(name=model_name)\n",
"container_def = model.prepare_container_def()\n",
"sagemaker_session.create_model(model_name, role, container_def)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Amazon SageMaker Clarify\n",
"With your model set up, it's time to explore SageMaker Clarify. For a general overview of how SageMaker Clarify processing jobs work, refer [the provided link](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-processing-job-configure-how-it-works.html). "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:sagemaker.image_uris:Defaulting to the only supported framework/algorithm version: 1.0.\n",
"INFO:sagemaker.image_uris:Ignoring unnecessary instance type: None.\n"
]
}
],
"source": [
"from sagemaker import clarify\n",
"\n",
"# Initialize a SageMakerClarifyProcessor to compute bias metrics and model explanations.\n",
"clarify_processor = clarify.SageMakerClarifyProcessor(\n",
" role=role, instance_count=1, instance_type=\"ml.m5.xlarge\", sagemaker_session=sagemaker_session\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Detecting Bias\n",
"SageMaker Clarify helps you detect possible [pre-training](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-detect-data-bias.html) and [post-training](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-detect-post-training-bias.html) biases using a variety of metrics.\n",
"\n",
"#### Writing DataConfig\n",
"A [DataConfig](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.DataConfig) object communicates some basic information about data I/O to SageMaker Clarify. For our example here we provide the below information:\n",
"\n",
"* `s3_data_input_path`: S3 URI of the train dataset we uploaded above\n",
"* `s3_output_path`: S3 URI at which our output report will be uploaded\n",
"* `label`: Specifies the ground truth label, which is also known as observed label or target attribute. It is used for many bias metrics. In this example, the `Target` column has the ground truth label.\n",
"* `headers`: The list of column names in the dataset\n",
"* `dataset_type`: specifies the format of your dataset, for this example as we are using CSV dataset this will be `text/csv`"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"bias_report_output_path = \"s3://{}/{}/clarify-bias\".format(bucket, prefix)\n",
"bias_data_config = clarify.DataConfig(\n",
" s3_data_input_path=train_uri,\n",
" s3_output_path=bias_report_output_path,\n",
" label=\"Target\",\n",
" headers=training_data.columns.to_list(),\n",
" dataset_type=\"text/csv\",\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Writing ModelConfig\n",
"\n",
"A [ModelConfig](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.ModelConfig) object communicates information about your trained model. To avoid additional traffic to the production models, SageMaker Clarify sets up and tears down a dedicated endpoint when processing. For our example here we provide the below information:\n",
"\n",
"* `model_name`: name of the concerned model, using name of the xgboost model trained earlier\n",
"* `instance_type` and `initial_instance_count` specify your preferred instance type and instance count used to run your model on during SageMaker Clarify's processing. The example dataset is small, so a single standard instance is good enough to run this example.\n",
"* `accept_type` denotes the endpoint response payload format, and `content_type` denotes the payload format of request to the endpoint. As per the example model we created above both of these will be `text/csv`."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"model_config = clarify.ModelConfig(\n",
" model_name=model_name,\n",
" instance_type=\"ml.m5.xlarge\",\n",
" instance_count=1,\n",
" accept_type=\"text/csv\",\n",
" content_type=\"text/csv\",\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Writing ModelPredictedLabelConfig\n",
"\n",
"A [ModelPredictedLabelConfig](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.ModelPredictedLabelConfig) provides information on the format of your predictions. XGBoost model outputs probabilities of samples, so SageMaker Clarify invokes the endpoint then uses `probability_threshold` to convert the probability to binary labels for bias analysis. Prediction above the threshold is interpreted as label value `1` and below or equal as label value `0`."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"predictions_config = clarify.ModelPredictedLabelConfig(probability_threshold=0.8)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Writing BiasConfig\n",
"[BiasConfig](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.BiasConfig) contains configuration values for detecting bias using a Clarify container."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"bias_config = clarify.BiasConfig(\n",
" label_values_or_threshold=[1], facet_name=\"Sex\", facet_values_or_threshold=[0], group_name=\"Age\"\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"For our demo we provide the following information in BiasConfig API:\n",
"\n",
"* `label_values_or_threshold`: List of label value(s) or threshold to indicate positive outcome used for bias metrics. Here positive outcome is earning >$50,000.\n",
"* `facet_name`: Sensitive columns of the dataset, \"Sex\" is the category\n",
"* `facet_values_or_threshold`: values of the sensitive group, \"Female\" respondents are the sensitive group.\n",
"* `group_name`: This example has selected the \"Age\" column which is used to form subgroups for the measurement of bias metric [Conditional Demographic Disparity (CDD)](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-data-bias-metric-cddl.html) or [Conditional Demographic Disparity in Predicted Labels (CDDPL)](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-post-training-bias-metric-cddpl.html).\n",
"\n",
"SageMaker Clarify can handle both categorical and continuous data for `facet: values_or_threshold` and for `label_values_or_threshold`. In this case we are using categorical data. The results will show if the model has a preference for records of one sex over the other."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Pre-training Bias\n",
"Bias can be present in your data before any model training occurs. Inspecting your data for bias before training begins can help detect any data collection gaps, inform your feature engineering, and help you understand what societal biases the data may reflect.\n",
"\n",
"Computing pre-training bias metrics does not require a trained model.\n",
"\n",
"#### Post-training Bias\n",
"Computing post-training bias metrics does require a trained model.\n",
"\n",
"Unbiased training data (as determined by concepts of fairness measured by bias metric) may still result in biased model predictions after training. Whether this occurs depends on several factors including hyperparameter choices.\n",
"\n",
"\n",
"You can run these options separately with [run_pre_training_bias()](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.SageMakerClarifyProcessor.run_pre_training_bias) and [run_post_training_bias()](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.SageMakerClarifyProcessor.run_post_training_bias) or at the same time with `run_bias()` as shown below. We use following additional parameters for the api call:\n",
"\n",
"* `pre_training_methods`: Pre-training bias metrics to be computed. The detailed description of the metrics can be found on [Measure Pre-training Bias](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-measure-data-bias.html). This example sets methods to \"all\" to compute all the pre-training bias metrics.\n",
"* `post_training_methods`: Post-training bias metrics to be computed. The detailed description of the metrics can be found on [Measure Post-training Bias](https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-detect-post-training-bias.html). This example sets methods to \"all\" to compute all the post-training bias metrics."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The job takes about 10 minutes to run\n",
"clarify_processor.run_bias(\n",
" data_config=bias_data_config,\n",
" bias_config=bias_config,\n",
" model_config=model_config,\n",
" model_predicted_label_config=predictions_config,\n",
" pre_training_methods=\"all\",\n",
" post_training_methods=\"all\",\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Viewing the Bias Report\n",
"In Studio, you can view the results under the experiments tab.\n",
"\n",
"\n",
"\n",
"Each bias metric has detailed explanations with examples that you can explore.\n",
"\n",
"\n",
"\n",
"You could also summarize the results in a handy table!\n",
"\n",
"\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"If you're not a Studio user yet, you can access the bias report in PDF, HTML and ipynb formats in the following S3 bucket:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'s3://sagemaker-ap-south-1-000000000000/sagemaker/DEMO-sagemaker-clarify/clarify-bias'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bias_report_output_path"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Explaining Predictions\n",
"There are expanding business needs and legislative regulations that require explanations of _why_ a model made the decision it did. SageMaker Clarify uses Kernel SHAP to explain the contribution that each input feature makes to the final decision.\n",
"\n",
"For run_explainability API call we need similar `DataConfig` and `ModelConfig` objects we defined above. [SHAPConfig](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.SHAPConfig) here is the config class for Kernel SHAP algorithm.\n",
"\n",
"For our demo we pass the following information in `SHAPConfig`:\n",
"\n",
"* `baseline`: Kernel SHAP algorithm requires a baseline (also known as background dataset). If not provided, a baseline is calculated automatically by SageMaker Clarify using K-means or K-prototypes in the input dataset. Baseline dataset type shall be the same as dataset_type, and baseline samples shall only include features. By definition, baseline should either be a S3 URI to the baseline dataset file, or an in-place list of samples. In this case we chose the latter, and put the mean of the train dataset to the list. For more details on baseline selection please [refer this documentation](https://docs.aws.amazon.com/en_us/sagemaker/latest/dg/clarify-feature-attribute-shap-baselines.html).\n",
"* `num_samples`: Number of samples to be used in the Kernel SHAP algorithm. This number determines the size of the generated synthetic dataset to compute the SHAP values. \n",
"* `agg_method`: Aggregation method for global SHAP values. For our example here we are using `mean_abs` i.e. mean of absolute SHAP values for all instances\n",
"* `save_local_shap_values`: Indicates whether to save the local SHAP values in the output location. Default is True."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"explainability_output_path = \"s3://{}/{}/clarify-explainability\".format(bucket, prefix)\n",
"explainability_data_config = clarify.DataConfig(\n",
" s3_data_input_path=train_uri,\n",
" s3_output_path=explainability_output_path,\n",
" label=\"Target\",\n",
" headers=training_data.columns.to_list(),\n",
" dataset_type=\"text/csv\",\n",
")\n",
"\n",
"baseline = [training_data.mean().iloc[1:].values.tolist()]\n",
"shap_config = clarify.SHAPConfig(\n",
" baseline=baseline,\n",
" num_samples=15,\n",
" agg_method=\"mean_abs\",\n",
" save_local_shap_values=True,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The job takes about 10 minutes to run\n",
"clarify_processor.run_explainability(\n",
" data_config=explainability_data_config,\n",
" model_config=model_config,\n",
" explainability_config=shap_config,\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Viewing the Explainability Report\n",
"As with the bias report, you can view the explainability report in Studio under the experiments tab.\n",
"\n",
"\n",
"\n",
"\n",
"The Model Insights tab contains direct links to the report and model insights.\n",
"\n",
"If you're not a Studio user yet, as with the Bias Report, you can access this report at the following S3 bucket."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'s3://sagemaker-ap-south-1-000000000000/sagemaker/DEMO-sagemaker-clarify/clarify-explainability'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"explainability_output_path"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Analysis of local explanations\n",
"It is possible to visualize the local explanations for single examples in your dataset. You can use the obtained results from running Kernel SHAP algorithm for global explanations.\n",
"\n",
"You can simply load the local explanations stored in your output path, and visualize the explanation (i.e., the impact that the single features have on the prediction of your model) for any single example."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:botocore.credentials:Found credentials from IAM Role: BaseNotebookInstanceEc2InstanceRole\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Example number: 111 \n",
"with model prediction: False\n",
"\n",
"Feature values -- Label Target 0\n",
"Age 21\n",
"Workclass 2\n",
"fnlwgt 199915\n",
"Education 15\n",
"Education-Num 10\n",
"Marital Status 4\n",
"Occupation 7\n",
"Relationship 3\n",
"Ethnic group 4\n",
"Sex 0\n",
"Capital Gain 0\n",
"Capital Loss 0\n",
"Hours per week 40\n",
"Country 38\n",
"Name: 120, dtype: int64\n"
]
},
{
"data": {
"text/plain": [
""
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAFMCAYAAAA++EC6AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8/fFQqAAAACXBIWXMAAAsTAAALEwEAmpwYAAA4hElEQVR4nO3dedxmc/3H8dd7ZjCWxjrJPmKk4RdprEnJki20CCFRoVVpIy1+UiT9JL8iIksi8hMV2feIGbuQScpYh7KUnc/vj+/3Mue+XOfezve6F/N+Ph73477Oua7zOee+7us6n3O+qyICMzOzTsYM9wGYmdnI5SRhZma1nCTMzKyWk4SZmdVykjAzs1pOEmZmVstJYhSQ9C5JM4d4n5MkhaRxQ7nfvO+dJF3QpdiflPSwpH9LWrQL8YftfRsOo+XvlXSApF8M93GMRk4SgyTpXkkbD/dxjHadTjIRcUpEbNqFfc0F/A+waUQsEBGPFYjpz4EhaUNJl0p6QtK9HZ7/tqRbJb0o6YC255aQdI6kB/J3YdIQHXa/OEnYnGRxYDxw+0A3VOLvi1Fz1/Qf4HjgyzWbzQC+Avy+w3MvA38APlDkAAvzh74wSfNI+mG+KnggP56n8vw2km6S9KSkv0raLK/fTdIdkp6SdI+kPQewz5UlXSjpn5LukvShvH6FvG6NvLykpEclvSsvXybpYEnX5SugsyUtUrOP2uNrFYdJ+qKkRyQ9KGm3yvNbSrox/833tV1JXZF/P56LgNaV9FFJV1W2X0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K3I2KDylO/lXRFw9ijYlx+m6M9moeWPzUv70i5Yci7yl8uG2oT83DYAEhaHpg4jMdjNhR2J80p8RBpfpAP5nUjnoubbEhJ2ow0X8I9edUkUme684ftoMyslpOEDbncEmnlvHhnRDw3nMdj1i2SjqT3BhtNp9btOhc32ZCQ9JXK4tYRcXP+eU7Sd4ftwMy6axppYMLpwNaVx62fEc93EjYkXguDzJk1MdJH3K3jOwkbKqp53GnZ7LVoVF6RO0nYUImax52WzWyEcHGTDQkPV21zorbJhuaj5+d+VHT0dJIwM7NaLm4yM7NaThJmZlbLScLMzGo5SZiZWS0nCTMzq/X/iNMnelxiHoYAAAAASUVORK5CYII=",
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"local_explanations_out = pd.read_csv(explainability_output_path + \"/explanations_shap/out.csv\")\n",
"feature_names = [str.replace(c, \"_label0\", \"\") for c in local_explanations_out.columns.to_series()]\n",
"local_explanations_out.columns = feature_names\n",
"\n",
"selected_example = 111\n",
"print(\n",
" \"Example number:\",\n",
" selected_example,\n",
" \"\\nwith model prediction:\",\n",
" sum(local_explanations_out.iloc[selected_example]) > 0,\n",
")\n",
"print(\"\\nFeature values -- Label\", training_data.iloc[selected_example])\n",
"local_explanations_out.iloc[selected_example].plot(\n",
" kind=\"bar\", title=\"Local explanation for the example number \" + str(selected_example), rot=90\n",
")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** You can run both bias and explainability jobs at the same time with `run_bias_and_explainability()`, refer [API Documentation](https://sagemaker.readthedocs.io/en/stable/api/training/processing.html#sagemaker.clarify.SageMakerClarifyProcessor.run_bias_and_explainability) for more details. "
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"### Clean Up\n",
"Finally, don't forget to clean up the resources we set up and used for this demo!"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:sagemaker:Deleting model with name: DEMO-clarify-model-07-02-2023-05-57-08\n"
]
}
],
"source": [
"sagemaker_session.delete_model(model_name)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Notebook CI Test Results\n",
"\n",
"This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"metadata": {
"instance_type": "ml.t3.medium",
"kernelspec": {
"display_name": "Python 3 (Data Science 3.0)",
"language": "python",
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/sagemaker-data-science-310-v1"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}