Skip to content

Commit b6cfa7c

Browse files
committed
feat: add logo
1 parent 000af8d commit b6cfa7c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2025 Spanish National Research Council (CSIC)
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
import typing
18+
import numpy as np
19+
import pandas as pd
20+
from pycanon import anonymity
21+
from pycanon.anonymity.utils import aux_anonymity
22+
23+
def average_rir(
24+
data_anon: pd.DataFrame,
25+
quasi_ident: typing.Union[typing.List, np.ndarray]
26+
) -> float:
27+
""" Calculate the average re-identification risk metric
28+
29+
:param data_anon: dataframe with the data anonymized.
30+
:type data_anon: pandas dataframe
31+
32+
:param quasi_ident: list with the name of the columns of the dataframe
33+
that are quasi-identifiers.
34+
:type quasi_ident: list of strings
35+
"""
36+
equiv_class = aux_anonymity.get_equiv_class(data_anon, quasi_ident)
37+
avg_rir = np.mean([1/len(ec) for ec in equiv_class])
38+
return avg_rir
39+
40+

0 commit comments

Comments
 (0)