You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
9.7 KiB
Python
256 lines
9.7 KiB
Python
6 years ago
|
"""
|
||
|
Health Information Privacy Lab
|
||
6 years ago
|
@TODO:
|
||
6 years ago
|
sample = args['sample'] if 'sample' in args else pd.DataFrame(self._df)
|
||
6 years ago
|
if not args or 'cols' not in args:
|
||
6 years ago
|
merged_groups = pd.merge(xi,yi,on=cols,how='inner')
|
||
|
handle_population= Population()
|
||
|
handle_population.set('merged_groups',merged_groups)
|
||
|
|
||
|
r['pop. marketer'] = handle_population.marketer()
|
||
|
r['pitman risk'] = handle_population.pitman()
|
||
|
r['pop. group size'] = np.unique(yi.population_group_size).size
|
||
|
#
|
||
|
# At this point we have both columns for either sample,population or both
|
||
|
#
|
||
|
r['field count'] = len(cols)
|
||
|
return pd.DataFrame([r])
|
||
|
|
||
|
class Risk :
|
||
|
"""
|
||
|
This class is an abstraction of how we chose to structure risk computation i.e in 2 sub classes:
|
||
|
- Sample computes risk associated with a sample dataset only
|
||
|
- Population computes risk associated with a population
|
||
|
"""
|
||
|
def __init__(self):
|
||
|
self.cache = {}
|
||
|
def set(self,key,value):
|
||
|
if id not in self.cache :
|
||
|
self.cache[id] = {}
|
||
|
self.cache[key] = value
|
||
|
|
||
|
class Sample(Risk):
|
||
|
"""
|
||
|
This class will compute risk for the sample dataset: the marketer and prosecutor risk are computed by default.
|
||
|
This class can optionally add pitman risk if the population size is known.
|
||
|
"""
|
||
|
def __init__(self):
|
||
|
Risk.__init__(self)
|
||
|
def marketer(self):
|
||
6 years ago
|
|
||
6 years ago
|
sample_row_count = r.sample_group_size.sum()
|
||
|
#
|
||
|
# @TODO : make sure the above line is size (not sum)
|
||
|
# sample_row_count = r.sample_group_size.size
|
||
|
return r.apply(lambda row: (row.sample_group_size / np.float64(row.population_group_size)) /np.float64(sample_row_count) ,axis=1).sum()
|