{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using ML anonymization to defend against attribute inference attacks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial we will show how to anonymize models using the ML anonymization module. \n", "\n", "We will demonstrate running inference attacks both on a vanilla model, and then on different anonymized versions of the model. We will run both black-box and white-box attribute inference attacks using ART's inference module (https://github.com/Trusted-AI/adversarial-robustness-toolbox/tree/main/art/attacks/inference). \n", "\n", "This will be demonstarted using the Nursery dataset (original dataset can be found here: https://archive.ics.uci.edu/ml/datasets/nursery). \n", "\n", "The sensitive feature we are trying to infer is the 'social' feature, after turning it into a binary feature (the original value 'problematic' receives the new value 1 and the rest 0). We also preprocess the data such that all categorical features are one-hot encoded." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load data" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": " parents has_nurs form children housing finance \\\n8450 pretentious very_crit foster 1 less_conv convenient \n12147 great_pret very_crit complete 1 critical inconv \n2780 usual critical complete 4 less_conv convenient \n11924 great_pret critical foster 1 critical convenient \n59 usual proper complete 2 convenient convenient \n... ... ... ... ... ... ... \n5193 pretentious less_proper complete 1 convenient inconv \n1375 usual less_proper incomplete 2 less_conv convenient \n10318 great_pret less_proper foster 4 convenient convenient \n6396 pretentious improper completed 3 less_conv convenient \n485 usual proper incomplete 1 critical inconv \n\n social health \n8450 1 not_recom \n12147 1 recommended \n2780 1 not_recom \n11924 1 not_recom \n59 0 not_recom \n... ... ... \n5193 0 recommended \n1375 1 priority \n10318 0 priority \n6396 1 recommended \n485 1 not_recom \n\n[10366 rows x 8 columns]", "text/html": "
| \n | parents | \nhas_nurs | \nform | \nchildren | \nhousing | \nfinance | \nsocial | \nhealth | \n
|---|---|---|---|---|---|---|---|---|
| 8450 | \npretentious | \nvery_crit | \nfoster | \n1 | \nless_conv | \nconvenient | \n1 | \nnot_recom | \n
| 12147 | \ngreat_pret | \nvery_crit | \ncomplete | \n1 | \ncritical | \ninconv | \n1 | \nrecommended | \n
| 2780 | \nusual | \ncritical | \ncomplete | \n4 | \nless_conv | \nconvenient | \n1 | \nnot_recom | \n
| 11924 | \ngreat_pret | \ncritical | \nfoster | \n1 | \ncritical | \nconvenient | \n1 | \nnot_recom | \n
| 59 | \nusual | \nproper | \ncomplete | \n2 | \nconvenient | \nconvenient | \n0 | \nnot_recom | \n
| ... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
| 5193 | \npretentious | \nless_proper | \ncomplete | \n1 | \nconvenient | \ninconv | \n0 | \nrecommended | \n
| 1375 | \nusual | \nless_proper | \nincomplete | \n2 | \nless_conv | \nconvenient | \n1 | \npriority | \n
| 10318 | \ngreat_pret | \nless_proper | \nfoster | \n4 | \nconvenient | \nconvenient | \n0 | \npriority | \n
| 6396 | \npretentious | \nimproper | \ncompleted | \n3 | \nless_conv | \nconvenient | \n1 | \nrecommended | \n
| 485 | \nusual | \nproper | \nincomplete | \n1 | \ncritical | \ninconv | \n1 | \nnot_recom | \n
10366 rows × 8 columns
\n| \n | parents | \nhas_nurs | \nform | \nchildren | \nhousing | \nfinance | \nsocial | \nhealth | \n
|---|---|---|---|---|---|---|---|---|
| 0 | \npretentious | \nvery_crit | \nfoster | \n1 | \nless_conv | \nconvenient | \n0 | \nnot_recom | \n
| 1 | \ngreat_pret | \nvery_crit | \ncomplete | \n1 | \ncritical | \ninconv | \n1 | \nrecommended | \n
| 2 | \nusual | \ncritical | \ncomplete | \n4 | \nless_conv | \nconvenient | \n0 | \nnot_recom | \n
| 3 | \ngreat_pret | \ncritical | \nfoster | \n1 | \ncritical | \nconvenient | \n0 | \nnot_recom | \n
| 4 | \nusual | \nproper | \ncomplete | \n2 | \nconvenient | \nconvenient | \n0 | \nnot_recom | \n
| ... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n... | \n
| 10361 | \npretentious | \nless_proper | \ncomplete | \n1 | \nconvenient | \ninconv | \n0 | \nrecommended | \n
| 10362 | \nusual | \nless_proper | \nincomplete | \n2 | \nless_conv | \nconvenient | \n1 | \npriority | \n
| 10363 | \ngreat_pret | \nless_proper | \nfoster | \n4 | \nconvenient | \nconvenient | \n0 | \npriority | \n
| 10364 | \npretentious | \nimproper | \ncompleted | \n3 | \nless_conv | \nconvenient | \n1 | \nrecommended | \n
| 10365 | \nusual | \nproper | \nincomplete | \n1 | \ncritical | \nconvenient | \n0 | \nnot_recom | \n
10366 rows × 8 columns
\n