return classifier if __name__ == "__main__": if len(sys.argv) != 4: print >> sys.stderr, "Usage: classify.py [TAB_FILE] [classifier: tree, bayes, svm, logreg] [number to filter, 0 -> no filtering]" sys.exit(1) data = proj_utils.load_data(sys.argv[1]) type = sys.argv[2] features = int(sys.argv[3]) train_data, test_data = proj_utils.partition_data(data) model = train_classifier(train_data, type, features) train_CA, train_results = proj_utils.test_classifier(model, train_data) test_CA, test_results = proj_utils.test_classifier(model, test_data) #print "Train Accuracy: %f, Test Accuracy: %f" % (train_CA, test_CA) train_stats = proj_utils.get_stats(train_results) test_stats = proj_utils.get_stats(test_results) print "Train:\n%s" % str(train_stats) print "\nTest:\n%s" % str(test_stats) if features != 0: print "Features selected:\n%s" % str(model.domain) filename = '%s%sresults%s%s_filtered_%s.txt' % ( os.path.dirname(__file__), os.sep, os.sep, type, str(features) ) #+ type + '_filtered_' + str(features) + '.txt' else:
return classifier if __name__ == "__main__": if len(sys.argv) != 4: print >> sys.stderr, "Usage: classify.py [TAB_FILE] [classifier: tree, bayes, svm, logreg] [number to filter, 0 -> no filtering]" sys.exit(1) data = proj_utils.load_data(sys.argv[1]) type = sys.argv[2] features = int(sys.argv[3]) train_data, test_data = proj_utils.partition_data(data) model = train_classifier(train_data, type, features) train_CA, train_results = proj_utils.test_classifier(model, train_data) test_CA, test_results = proj_utils.test_classifier(model, test_data) #print "Train Accuracy: %f, Test Accuracy: %f" % (train_CA, test_CA) train_stats = proj_utils.get_stats(train_results) test_stats = proj_utils.get_stats(test_results) print "Train:\n%s" % str(train_stats) print "\nTest:\n%s" % str(test_stats) if features != 0: print "Features selected:\n%s" % str(model.domain) filename = '%s%sresults%s%s_filtered_%s.txt' % (os.path.dirname(__file__), os.sep, os.sep, type, str(features)) #+ type + '_filtered_' + str(features) + '.txt' else: filename = '%s%sresults%s%s.txt' % (os.path.dirname(__file__), os.sep, os.sep, type) print filename