eltneg

decision_tree_nl

May 7th, 2018
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. from itertools import combinations
  2.  
  3. def dec_tree(digit):
  4.     res = [tuple(x for x in range(digit))]
  5.     while len(min(res)) != 1:
  6.         new_list = []
  7.         for item in res:
  8.             new_list.extend(combinations(item, len(min(res)) - 1))
  9.         res.extend(new_list)
  10.     return sorted([list(x) for x in set(sorted(res))])
  11.    
  12. assert dec_tree(2) == sorted([[0], [1], [0,1]])
  13. assert dec_tree(3) == sorted([[0], [1], [2], [0,1], [0,2], [1,2], [0,1,2]])
  14. assert dec_tree(4) == sorted(
  15.     [[0], [1], [2], [3], [0, 1], [0, 2], [0, 3], [1, 2],
  16.     [1, 3], [2, 3], [0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3], [0, 1, 2, 3]])
Advertisement
Add Comment
Please, Sign In to add comment