def back_end_process(prefix,base_prefix,faction=""): """Do processing specific to a faction or else process a file for "all". """ # This command is needed to, in particular, strip out unneeded values from the RECRUITED column command = "waffles_transform dropunusedvalues " + sh_escape(prefix) + ".arff" step1 = strip_quotes.sub('', prefix) clean_prefix = space_to_underscore.sub("_",step1) if not faction: matched = re.match("__[^_]*_(.*)",clean_prefix) faction = matched.group(1) print "Now processing the faction: " + str(faction) temp4_filename = "__temp4_" + faction + ".arff" do_command(command,True,temp4_filename) final_prefix = base_prefix + "_" + faction command = "waffles_transform drophomogcols {0}".format(temp4_filename) do_command(command,True,final_prefix + ".arff") command = "waffles_learn train -seed 0 {0}.arff neuralnet {1}".format(final_prefix,options.neural_net_parms) do_command(command,True,final_prefix + ".json")
(options, args) = parser.parse_args() if (len(args) != 1): parser.error("Incorrect number of arguments. Requires one .csv file as an argument. Run with --help for help") input_file = args[0].strip() current_directory = "." assert input_file.endswith(".csv"),"Input must be a .csv file!" assert input_file in os.listdir(current_directory), input_file + " not found in current directory!" m = re.match("(.*)\.csv",input_file) file_prefix = m.group(1) temp0_file = "__temp0.csv" if temp0_file not in os.listdir(current_directory): if options.retain_default: command = "cp " + sh_escape(input_file) + temp0_file do_command(command,True) else: command = "grep -v default " + sh_escape(input_file) do_command(command,True,temp0_file) main_arff_file = file_prefix + ".arff" if main_arff_file not in os.listdir(current_directory): command = "waffles_transform import {0} -columnnames".format(temp0_file) do_command(command,True,main_arff_file) columns = get_schema_from_arff(main_arff_file) metric = columns.index(options.metric)
usage = "Turns a normalized .csv file (produced by csv_normalizer) into a .arff file suitable for training\n" + \ "usage: %prog [options] input.arff" parser = OptionParser(usage) parser.add_option("-f","--faction",dest="faction",help="Faction you want to learn a model for. Defaults to build a model for all factions.") parser.add_option("-r","--retain",dest="retain_temporary",help="Retain temporary files?",action="store_true",default=False) (options, args) = parser.parse_args() if options.faction == "'Knalgan Alliance'": faction = Knalgan else: faction = options.faction # Strip out unneeded values from the RECRUITED column command = "waffles_transform dropunusedvalues " + sh_escape(args[0]) + "_" + sh_escape(args[1]) do_command(command,True,"__temp10_" + faction + ".arff") command = "waffles_transform drophomogcols __temp10_" + faction + ".arff" do_command(command,True,"__temp11_" + faction + ".arff") command = "waffles_learn train -seed 0 __temp11_{0}.arff neuralnet -addlayer {1:d}".format(faction,options.layers) do_command(command,True,"" "__temp11_" + faction + ".arff") if not options.retain_temporary: subprocess.call("rm __temp1* __temp2.arff __temp3.arff __temp4.arff",shell=True)