anonymizer.py 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. """
  3. run basic_mondrian with given parameters
  4. """
  5. import copy
  6. import sys
  7. import os
  8. from basic_mondrian.mondrian import mondrian
  9. sys.path.insert(1, os.path.join(sys.path[0], '..'))
  10. from utils.data import reorder_columns, restore_column_order
  11. DATA_SELECT = 'a'
  12. DEFAULT_K = 10
  13. def extend_result(val):
  14. """
  15. separated with ',' if it is a list
  16. """
  17. if isinstance(val, list):
  18. return ','.join(val)
  19. return val
  20. def get_result_one(att_trees, data, k, path, qi_index, SA_index):
  21. "run basic_mondrian for one time, with k=10"
  22. print("K=%d" % k)
  23. print("Mondrian")
  24. result, eval_result = mondrian(att_trees, reorder_columns(
  25. copy.deepcopy(data), qi_index), k, len(qi_index), SA_index)
  26. print("NCP %0.2f" % eval_result[0] + "%")
  27. print("Running time %0.2f" % eval_result[1] + "seconds")
  28. return restore_column_order(result, qi_index), eval_result[0], eval_result[1]