def handle_train(argv): examples = process_file(argv[2], training=True) tree = None if argv[4] == "dt": tree = DecisionTree() else: tree = Adaboost() tree.define_positive_class(lambda x: x.classification == 'en') tree.define_classes(processing.classes) tree.define_attributes(processing.attr_definitions) tree.load_examples(examples) tree.generate(tree.examples) with open(argv[3], "w") as f: f.write(argv[4] + "\n") f.write(str(tree.tree)) f.close() tree.print()
def handle_train(argv, size=None, depth=None): examples = process_file(argv[2], training=True) tree = None tree = DecisionTree() tree.define_positive_class(lambda x: x.classification == 'en') tree.define_classes(processing.classes) tree.define_attributes(processing.attr_definitions) if size: tree.load_examples(examples[:size]) else: tree.load_examples(examples) if depth != None: tree.generate(tree.examples, depth) else: tree.generate(tree.examples) with open(argv[3], "w") as f: f.write("dt" + "\n") f.write(str(tree.tree)) f.close() tree.print()