trasgodp.categorical package¶
Module contents¶
DP Exponential mechanism for categorical columns.
- trasgodp.categorical.dp_exponential(df: DataFrame, column: str, epsilon: float, new_column=False) DataFrame¶
Apply the Exponential mechanism to a categorical column of a dataframe.
- Parameters:
df (pandas dataframe) – dataframe with the data under study.
columm (string) – column to which the DP mechanism will be applied.
epsilon (float) – privacy budget.
new_column (boolean) – boolean, default to False. If False, the new values obtained with the mechanims applied are stored in the same column. If True, a new column ‘dp_{column}’ is created with the new values.
- Returns:
dataframe with the column transformed applying the mechanism.
- Return type:
pandas dataframe.
- trasgodp.categorical.dp_exponential_array(data: List | ndarray, epsilon: float) ndarray¶
Apply the Exponential mechanism to an array with categorical values.
- Parameters:
data (list or numpy array) – dataset with the data under study.
epsilon (float) – privacy budget.
- Returns:
array with data transformed applying the mechanism.
- Return type:
numpy array.
- trasgodp.categorical.dp_randomized_response_binary(df: DataFrame, column: str, epsilon: float, new_column=False, positive_label=None) DataFrame¶
Apply the Randomized Response mechanism to a binary column of a dataframe.
- Parameters:
df (pandas dataframe) – dataframe with the data under study.
columm (string) – column to which the DP mechanism will be applied. Binary data.
epsilon (float) – privacy budget.
new_column (boolean) – boolean, default to False. If False, the new values obtained with the mechanims applied are stored in the same column. If True, a new column ‘dp_{column}’ is created with the new values.
positive_label (string) – value to be assigned as 1. If None, it is assigned to first value.
- Returns:
dataframe with the column transformed applying the mechanism.
- Return type:
pandas dataframe.
- trasgodp.categorical.dp_randomized_response_binary_array(data: list | ndarray, epsilon: float, positive_label=None) ndarray¶
Apply the binary randomized response mechanism to a list or numpy array.
- Parameters:
data (list or numpy array) – dataset with the data under study.
epsilon (float) – privacy budget.
positive_label (string) – value to be assigned as 1. If None, it is assigned to first value.
- Returns:
array with the data transformed applying the binary RR mechanism.
- Return type:
numpy array.
- trasgodp.categorical.dp_randomized_response_kary(df: DataFrame, column: str, epsilon: float, new_column=False) DataFrame¶
Apply the Randomized Response mechanism to column of a dataframe (no binary).
- Parameters:
df (pandas dataframe) – dataframe with the data under study.
columm (string) – column to which the DP mechanism will be applied. Binary data.
epsilon (float) – privacy budget.
new_column (boolean) – boolean, default to False. If False, the new values obtained with the mechanims applied are stored in the same column. If True, a new column ‘dp_{column}’ is created with the new values.
- Returns:
dataframe with the column transformed applying the mechanism.
- Return type:
pandas dataframe.
- trasgodp.categorical.dp_randomized_response_kary_array(data: list | ndarray, epsilon: float) ndarray¶
Apply the k-ary Randomized Response mechanism to a list or numpy array.
- Parameters:
data (list or numpy array) – dataset with the data under study.
epsilon (float) – privacy budget.
positive_label (string) – value to be assigned as 1. If None, it is assigned to first value.
- Returns:
array with the data transformed applying the k-ary RR mechanism.
- Return type:
numpy array.