anjana.anonymity.utils package¶
Submodules¶
anjana.anonymity.utils.utils module¶
Module with utils for the anonymization tools.
- anjana.anonymity.utils.utils.apply_hierarchy(data: list | ndarray, hierarchies: dict, level: int) list | ndarray¶
Apply the given level of a hierarchy for a quasi-identifier.
- Parameters:
data (list, numpy array) – data under study.
hierarchies (dictionary with the hierarchies and the levels) – hierarchies for generalizing a given QI.
level (int) – level of the hierarchy to be applied.
- Returns:
column with the given level of hierarchy applied.
- Return type:
numpy array
- anjana.anonymity.utils.utils.apply_hierarchy_current(data: list | ndarray, hierarchies: dict, level: int, actual: int) list | ndarray¶
Apply certain level of a hierarchy for a quasi-identifier given the current one.
- Parameters:
data (list, numpy array) – data under study.
hierarchies (dictionary with the hierarchies and the levels) – hierarchies for generalizing a given QI.
level (int) – level of the hierarchy to be applied.
actual (int) – current level of the hierarchy applied.
- Returns:
column with the given level of hierarchy applied.
- Return type:
numpy array
- anjana.anonymity.utils.utils.apply_transformation(data: DataFrame, quasi_ident: list | ndarray, hierarchies: dict, transformation: list) DataFrame¶
Apply a given transformation to the data.
- Parameters:
data (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
transformation (list) – transformation to be applied
- Returns:
dataset generalized with the transformation given
- Return type:
pandas dataframe
- anjana.anonymity.utils.utils.check_gen_level(data: DataFrame, quasi_ident: list | ndarray, hierarchies: dict) dict¶
Check the generalization level for each quasi-identifier.
- Parameters:
data (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
- Returns:
level of generalization applied to each QI.
- Return type:
dict
- anjana.anonymity.utils.utils.generate_intervals(quasi_ident: list | ndarray, inf: int | float, sup: int | float, step: int) list¶
Generate intervals as hierarchies.
Given a quasi-identifier of numeric type, creates a list containing an interval-based generalization (hierarchy) of the values of the quasi-identifier. The intervals will have the length entered in step.
- Parameters:
quasi_ident (list or numpy array) – values of the quasi-identifier on which the interval-based generalization is to be obtained
inf (int or float) – lower value of the set of intervals
sup (int or float) – bigger value of the set of intervals
step (int) – spacing between values of the intervals
- Returns:
list with the intervals associated with the given values
- Return type:
list
- anjana.anonymity.utils.utils.get_transformation(data_anon: DataFrame, quasi_ident: list | ndarray, hierarchies: dict) list¶
Get the transformation applied for anonymizing the data.
Example: a transformation [0,1,2,0] means: - Level 0 of generalization for th 1st QI - Level 1 of generalization for th 2nd QI - Level 2 of generalization for th 3rd QI - Level 0 of generalization for the 4th QI
- Parameters:
data_anon (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
- Returns:
transformation applied
- Return type:
list
- anjana.anonymity.utils.utils.suppress_identifiers(data: DataFrame, ident: list | ndarray) DataFrame¶
Remove the identifiers from a dataset.
- Parameters:
data (pandas dataframe) – data under study.
ident (list of strings) – list with the name of the columns of the dataframe that are identifiers.
- Returns:
data with the identifiers suppressed.
- Return type:
pandas dataframe
Module contents¶
Package containing auxiliary functions for performing the anonymization.
- anjana.anonymity.utils.apply_hierarchy(data: list | ndarray, hierarchies: dict, level: int) list | ndarray¶
Apply the given level of a hierarchy for a quasi-identifier.
- Parameters:
data (list, numpy array) – data under study.
hierarchies (dictionary with the hierarchies and the levels) – hierarchies for generalizing a given QI.
level (int) – level of the hierarchy to be applied.
- Returns:
column with the given level of hierarchy applied.
- Return type:
numpy array
- anjana.anonymity.utils.apply_transformation(data: DataFrame, quasi_ident: list | ndarray, hierarchies: dict, transformation: list) DataFrame¶
Apply a given transformation to the data.
- Parameters:
data (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
transformation (list) – transformation to be applied
- Returns:
dataset generalized with the transformation given
- Return type:
pandas dataframe
- anjana.anonymity.utils.check_gen_level(data: DataFrame, quasi_ident: list | ndarray, hierarchies: dict) dict¶
Check the generalization level for each quasi-identifier.
- Parameters:
data (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
- Returns:
level of generalization applied to each QI.
- Return type:
dict
- anjana.anonymity.utils.generate_intervals(quasi_ident: list | ndarray, inf: int | float, sup: int | float, step: int) list¶
Generate intervals as hierarchies.
Given a quasi-identifier of numeric type, creates a list containing an interval-based generalization (hierarchy) of the values of the quasi-identifier. The intervals will have the length entered in step.
- Parameters:
quasi_ident (list or numpy array) – values of the quasi-identifier on which the interval-based generalization is to be obtained
inf (int or float) – lower value of the set of intervals
sup (int or float) – bigger value of the set of intervals
step (int) – spacing between values of the intervals
- Returns:
list with the intervals associated with the given values
- Return type:
list
- anjana.anonymity.utils.get_transformation(data_anon: DataFrame, quasi_ident: list | ndarray, hierarchies: dict) list¶
Get the transformation applied for anonymizing the data.
Example: a transformation [0,1,2,0] means: - Level 0 of generalization for th 1st QI - Level 1 of generalization for th 2nd QI - Level 2 of generalization for th 3rd QI - Level 0 of generalization for the 4th QI
- Parameters:
data_anon (pandas dataframe) – data under study.
quasi_ident (list of strings) – list with the name of the columns of the dataframe that are quasi-identifiers.
hierarchies (dictionary containing one dictionary for QI with the hierarchies and the levels) – hierarchies for generalizing the QI.
- Returns:
transformation applied
- Return type:
list
- anjana.anonymity.utils.suppress_identifiers(data: DataFrame, ident: list | ndarray) DataFrame¶
Remove the identifiers from a dataset.
- Parameters:
data (pandas dataframe) – data under study.
ident (list of strings) – list with the name of the columns of the dataframe that are identifiers.
- Returns:
data with the identifiers suppressed.
- Return type:
pandas dataframe