[text] harness code

Viewer

copydownloadembedprintName: harness code
  1. import random
  2. import warnings
  3.  
  4. warnings.filterwarnings("ignore")
  5.  
  6. random.seed(0)
  7. np.random.seed(0)
  8.  
  9. def get_named_version(data):
  10.     named_columns = ['age', 'workclass', 'fnlwgt', 'education', 'education-num',
  11.        'marital-status', 'occupation', 'relationship', 'race', 'sex',
  12.        'capital-gain', 'capital-loss', 'hours-per-week', 'native-country',
  13.        'income']
  14.  
  15.     data_named = copy.deepcopy(data)
  16.     data_named.columns = named_columns
  17.  
  18.     return data_named
  19.  
  20. def eval_harness(real, synthetic, private_synthetic, random):
  21.  
  22.     real, synthetic, private_synthetic, random = [get_named_version(d) for d in [real, synthetic, private_synthetic, random]]
  23.     
  24.     def eval_single(real, synthetic, name='non-private'):
  25.         print('#' * 10 + f' {name} ' + '#' * 10)
  26.         print('chi-square =', CSTest.compute(real, synthetic), 'komolgorov-smirnov =', KSTest.compute(real, synthetic))
  27.         print('train syn test real =', MulticlassDecisionTreeClassifier.compute(real, synthetic, target='income'))
  28.  
  29.         train = real.sample(int(len(real) * 0.75), random_state=0)
  30.         test = real[~real.index.isin(train.index)]
  31.         print('train real test real =', MulticlassDecisionTreeClassifier.compute(test, train, target='income'))
  32.         print('1 - ROCAUC =', LogisticDetection.compute(real, synthetic))
  33.  
  34.         print()
  35.  
  36.     eval_single(real, random, name='random')
  37.     eval_single(real, synthetic, name='non-private')
  38.     eval_single(real, private_synthetic, name='private')

Editor

You can edit this paste and save as new:


File Description
  • harness code
  • Paste Code
  • 30 Jun-2022
  • 1.49 Kb
You can Share it: