#! /usr/bin/env python from format_data import formatData from train_xgboost import train import csv def loadFinalData(flag): dataCSV = csv.reader(open("../data/data_"+flag+".csv", "r")) data = [row for row in dataCSV] formatData(data[1:], flag) loadFinalData("train") loadFinalData("test") train("final")
from format_data import formatData from train_xgboost import train import csv dataCSV = csv.reader(open("../data/data_train.csv", "r")) data = [row for row in dataCSV] del data[0] m = (len(data)-1)//10+1 data_origin = [] for i in range(len(data)): data_origin.append(data[i][:2]) for k in range(10): left, right = k*m, min((k+1)*m, len(data)) realFile = open("real_value_"+str(k)+".csv", "w") lines = ["LKADT_P,DEATH\n"] for i in range(left, right): lines.append("{},{}\n".format(data[i][0], data[i][1])) realFile.writelines(lines) formatData(data[:left]+data[right:], "train") for i in range(left, right): data[i][0], data[i][1] = 0, 1 formatData(data[left:right], "test") for i in range(left, right): data[i][0], data[i][1] = data_origin[i] train(str(k))
value_train_dir = "{}/stage*/train_value".format(args.outdir) policy_train_dir = "{}/stage*/train_policy".format(args.outdir) value_train_dirs = glob.glob(value_train_dir) policy_train_dirs = glob.glob(policy_train_dir) T0 = time.time() if args.model_type == "xgboost": value_train_dirs = [d + "/svmlight" for d in value_train_dirs] policy_train_dirs = [d + "/svmlight" for d in policy_train_dirs] from train_xgboost import train if args.target_model in ("value", "all"): value_modelfile = "{}/value_xgb".format(args.outdir) print("\n\nTraining value model") train(args, value_train_dirs, value_modelfile, n_features, objective="reg:squarederror", oversample=True) if args.target_model in ("policy", "all"): policy_modelfile = "{}/policy_xgb".format(args.outdir) print("\n\nTraining policy model") train(args, policy_train_dirs, policy_modelfile, n_features, objective="reg:squarederror", oversample=True) elif args.model_type == "nn": value_train_dirs = [d + "/svmlight" for d in value_train_dirs] policy_train_dirs = [d + "/svmlight" for d in policy_train_dirs]
def train_xgboost(opt): import train_xgboost as xgboost team_data = get_team_representations(opt.team_data_type) xgboost.train(team_data, opt)