TEST_FILE = MID_FILE + '.test' try: # shutil.rmtree(SWEEP_DIR) os.mkdir(SWEEP_DIR) except: pass # build the feature vector ONCE if necessary os.system('./%s %s' % (BUILD_PROG, TRAIN_FILE)) CSteps = [0.25, 0.5, 1, 2, 4] GSteps = [0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128] # CSteps = [0.25, 0.5, 1, 2, 4] # GSteps = [0.25, 0.5, 1, 2, 4] for C in CSteps: for G in GSteps: print '\n\n** tuning paramers {C=%d, gamma=%d} **\n\n' % (C, G) os.system('./%s %s %s' % (TRAIN_PROG, str(C), str(G))) os.system('./%s %s' % (TEST_PROG, TEST_FILE)) # copy training & testing results # pdb.set_trace() copy_anything(RESULTS_DIR, os.path.join(SWEEP_DIR, '%s.C%s.G%s' % (RESULTS_DIR, str(C), str(G)))) # cleanup os.system('./clean_test_svm.sh')
movie_id = f_mlist.readline().strip() idx = 1 while (movie_id): if (idx in test_idx): f_test.write('%s\n' % movie_id) else: f_train.write('%s\n' % movie_id) movie_id = f_mlist.readline().strip() idx += 1 f_train.close() f_test.close() # now train/test on this partition if model_type == 'svm': BUILD_PROG = 'build_svm_imdb.py' os.system('./%s %s' % (BUILD_PROG, train_file)) os.system('./%s 2 2' % TRAIN_PROG) else: os.system('./%s %s' % (TRAIN_PROG, train_file)) os.system('./%s %s' % (TEST_PROG, test_file)) # copy training & testing results copy_anything(MODEL_DIR, os.path.join(XVAL_DIR, '%s.K%s' % (MODEL_DIR, k))) copy_anything(RESULTS_DIR, os.path.join(XVAL_DIR, '%s.K%s' % (RESULTS_DIR, k))) # clean training & testing results call(['./clean_train_%s.sh' % model_type]) call(['./clean_test_%s.sh' % model_type])