fork download
  1.  final int num_lists = 3;
  2. ArrayList<String> list_as[] = new ArrayList<String>[3];
  3. for (int i = 0; i < num_lists; ++i)
  4. list_as[i] = new ArrayList<String>();
  5.  
  6. if (choice_needed)
  7. {
  8. best_attribute = choose_Attribute(examples, attributes);
  9. node.setData(Integer.toString(best_attribute)); //not hm.get(best_attribute)
  10. //create the children
  11.  
  12. Node<String> childs[] = new Node<String>[num_lists];
  13. for (int i = 0; i < num_lists; ++i)
  14. childs[i] = new Node<String>(null);
  15. for (int i = 0; i < num_lists; ++i)
  16. node.setChild(childs[i]);
  17.  
  18. //remove the best attribute
  19. for (int i=0; i<attributes.size(); i++)
  20. { if (attributes.get(i)==best_attribute)
  21. { attributes.remove(i);
  22. }
  23. }
  24.  
  25. //for each attribute type
  26. for (int i=0; i<num_lists; i++)
  27. { //create separate lists for each example type
  28. for (int j=0; j<num_examples; j++)
  29. { example = examples.get(j).split(",");
  30. int k = Integer.parseInt(example[best_attribute]);
  31. if (k < 0 || num_lists <= k)
  32. System.out.println("Something went wrong.");
  33. list_as[k].add(examples.get(j));
  34. }
  35.  
  36. DT_Learning(list_as[i], attributes, majority, childs[i]);
  37. }
  38. return node;
  39. }
  40.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty