classifiers['d2'] = classifier2 classifiers['d3'] = classifier3 classifiers['d4'] = classifier4 classifiers['d5'] = classifier5 classifiers['d6'] = classifier6 classifiers['d7'] = classifier7 classifiers['d8'] = classifier8 classifiers['d9'] = classifier9 classifiers['d10'] = classifier10 for c in classifiers.itervalues(): cm.train(c, training) perf = {} for n, c in classifiers.iteritems(): perf[n] = cm.perf([c], testing) print "Performances" print perf best_classifier_name = max(perf.iterkeys(), key=(lambda k: perf[k])) print "Best classifier: ", best_classifier_name, " -> ", perf[best_classifier_name] print "Saving the model" with open(args.dest_file, 'w') as f: cm.save(classifiers[best_classifier_name], f) except psycopg2.DatabaseError, e: print 'Error %s' % e sys.exit(1)
mySet = s.load(fe, args.number_pos, args.number_pos, args.number_neut) testingSet, _ = s.splitTrainingAndTestingSet(mySet, 1) # print testingSet.X, testingSet.Y except psycopg2.DatabaseError, e: print 'Error %s' % e sys.exit(1) finally: if con: con.close() # Testing the performance # Loading the classifiers path = args.origin_path list_classifier_filename = os.listdir(path) classifiers = [] # Retrieve the classifiers for classifier_filename in list_classifier_filename: with open(path + '/' + classifier_filename, 'r') as f: cm = ClassifierManager() classifier = cm.load(f) classifiers.append(classifier) # Evaluate the perfs print "Performance: ", cm.perf(classifiers, testingSet)