@@ -0,0 +1,1749 @@
+#!/usr/bin/env python%0A# -*- coding: UTF-8 -*-%0A# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:%0A# work with python 2.7%0A%0Afrom buildtree import tree_builder%0Aimport gzip%0Aimport argparse%0Aimport sys%0A%0A%0Adef load_test_data(path, tree):%0A%0A    test_data = %7B%7D%0A    for i in open(path):%0A        p_set = i.strip().split(',')%0A%0A        if len(p_set) != tree.attr_length:%0A            raise Exception(%22Test data feature length not equal to%22,%0A                            %22 attr length%22)%0A%0A        test_id = int(p_set%5B0%5D)%0A        data = map(float, p_set%5B0%5D)%0A        test_data%5Btest_id%5D = %7B'data': data, 'result': None%7D%0A%0A    return test_data%0A%0A%0Adef main():%0A    '''main: Main function%0A%0A    Description goes here.%0A    '''%0A    parser = argparse.ArgumentParser(description='Get socre from test files.')%0A    parser.add_argument('TRAIN_INPUT', nargs=1, help=%22Input data file%22)%0A    parser.add_argument('TEST_INPUT', nargs=1)%0A    parser.add_argument(%22OUTPUT%22, nargs=1, help=%22Output tree graph pdf%22)%0A    parser.add_argument(%0A        %22-d%22, dest='depth', default=-1, help=%22max depth%22, type=int)%0A    parser.add_argument('-g', default=False, action='store_true')%0A    args = parser.parse_args(sys.argv%5B1:%5D)%0A%0A    t = tree_builder(args.depth)%0A    t.load_data_from_file(args.TRAIN_INPUT%5B0%5D, args.g)%0A%0A    test_data = load_test_data(args.TEST_INPUT%5B0%5D, t)%0A%0A    print %22Finish load test_data with %25d entries%22 %25 len(test_data)%0A%0A    for i in test_data:%0A        result = t.classerify(test_data%5Bi%5D%5B'data'%5D)%0A%0A        test_data%5Bi%5D%5B'result'%5D = result%0A%0A    print %22Finish classification%22%0A%0A    fp = open(args.OUTPUT%5B0%5D, %22w%22)%0A%0A    for i in sorted(test_data.keys()):%0A        fp.write(%22%25s,%25s%5Cn%22 %25 (i, test_data%5Bi%5D%5B'result'%5D))%0A%0A    fp.close()%0A%0A    print %22Done!%22%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

fix bug and rename test_score