<jupyter_start><jupyter_text>Example analyzation and anonymization of sensitive dataset<jupyter_code>from pyarxaas import ARXaaS, Dataset
from pyarxaas.privacy_models import KAnonymity, LDiversityDistinct
from pyarxaas import AttributeType
import pandas as pd<jupyter_output><empty_output><jupyter_text>Create ARXaaS connection<jupyter_code># set logging level to INFO to show pyARXaas logging
import logging
logging.basicConfig(level=logging.INFO)
arxaas = ARXaaS('http://localhost:8080/') # connecting to online service<jupyter_output>INFO:pyarxaas.arxaas_connector:Connected to url=http://localhost:8080/ status=200<jupyter_text>fetch sensitive data<jupyter_code>data_df = pd.read_csv("../data/data2.csv", sep=";")
data_df = data_df[:6]
data_df<jupyter_output><empty_output><jupyter_text>Create Dataset<jupyter_code>dataset = Dataset.from_pandas(data_df)
dataset.describe()<jupyter_output>data:
  headers:
    ['zipcode', 'age', 'salary', 'disease']
rows:
    [47677, 29, 3, 'gastric ulcer']
    [47602, 22, 4, 'gastritis']
    [47678, 27, 5, 'stomach cancer']
    [47905, 43, 6, 'gastritis']
    [47909, 52, 11, 'flu']
    ...
attributes:
  field_name=zipcode, type=QUASIIDENTIFYING, hierarchy=None
  field_name=age, type=QUASIIDENTIFYING, hierarchy=None
  field_name=salary, type=QUASIIDENTIFYING, hierarchy=None
  field_name=disease, type=QUASIIDENTIFYING, hierarchy=None<jupyter_text>Set the AttributeType for the dataset fields<jupyter_code>dataset.set_attribute_type(AttributeType.IDENTIFYING, 'salary')<jupyter_output><empty_output><jupyter_text>Set Generalization HierarchiesNote that if the hierarchy does not have a header row in the csv file, please set header=None in read_csv() or the first row will be interpreted as a header and ARXaaS will throw an exception for the missing hierarchy data.<jupyter_code>zipcode_hierarchy = pd.read_csv("../data/data2_zipcode_hierarchy.csv", sep=";", header=None)
age_hierarchy = pd.read_csv("../data/data2_age_hierarchy.csv", sep=";", header=None)
disease_hierarchy = pd.read_csv("../data/data2_disease_hierarchy.csv", sep=";", header=None)
age_hierarchy
dataset.set_hierarchy("age", age_hierarchy)
dataset.set_hierarchy("zipcode", zipcode_hierarchy)
dataset.set_hierarchy("disease", disease_hierarchy)<jupyter_output><empty_output><jupyter_text>Create Privacy Models<jupyter_code>kanon = KAnonymity(2)<jupyter_output><empty_output><jupyter_text>Create Risk Profile<jupyter_code>risk_profile = arxaas.risk_profile(dataset)
risk_profile.re_identification_risk
risk_profile.distribution_of_risk_dataframe().head()<jupyter_output><empty_output><jupyter_text>Anonymize<jupyter_code>anon_result = arxaas.anonymize(dataset, [kanon])
anon_result.dataset.to_dataframe()<jupyter_output><empty_output><jupyter_text>Anonymization Status<jupyter_code>anon_result.anonymization_status<jupyter_output><empty_output><jupyter_text>RiskProfile for the anonymized dataset<jupyter_code>anon_rp = anon_result.risk_profile
anon_rp.re_identification_risk
anon_rp.distribution_of_risk_dataframe().head(10)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup