def ts_exp(common, binary, out_path): exp = Exp() lines = exp(None, binary, "A") lines += exp(common, binary, "F") exp = Exp(select_ens) lines += exp(common, binary, "H") files.save_txt(lines, out_path)
def full_exp(common, binary, out_path): if (type(binary) != list): binary = [binary] simple_exp = SimpleExp() lines = ["common,binary,n_clf,n_feats,accuracy,precision,recall,f1-score"] for binary_i in binary: lines += simple_exp(common, binary_i) files.save_txt(lines, out_path)
def exp_desc(paths,out_path=None,clf="LR",info="info",transform=None): all_systems=[systems.borda_count, systems.bucklin, systems.coombs] lines=[get_soft_voting(paths,clf,info,transform)] for system_i in all_systems: name_i=system_i.__name__ result_i=pref.ensemble(paths,system=system_i, clf=clf,transform=transform) lines.append(get_line(name_i,result_i,info)) if(out_path): files.save_txt(lines,out_path) else: print(lines)
def exp_template(datasets, clf, gens, loss, out_path): train = [data_i.split()[0] for data_i in datasets] names = list(train[0].keys()) lines = [] for info_i, gen_i in gens.items(): votes_i = get_votes(train, clf, names, gen_i) loss_i = {name_j: loss_j(votes_i) for name_j, loss_j in loss.items()} for info_j, loss_j in loss_i.items(): weights = optimize(loss_j, len(votes_i[0])) result_j = test_weights(datasets, clf, weights) metrics = exp.get_metrics(result_j) line_ij = "%s,%s,%s" % (info_i, info_j, metrics) print(line_ij) lines.append(line_ij) if (out_path): files.save_txt(lines, out_path) return lines
def save_dataset(common, binary, out_path): datasets = ens.read_dataset(common, binary) files.make_dir(out_path) subdirs = { desc_i: "%s/%s" % (out_path, desc_i) for desc_i in ["features", "votes"] } for path_i in subdirs.values(): files.make_dir(path_i) for i, data_i in enumerate(datasets): feat_i = "%s/%d" % (subdirs["features"], i) data_i.save(feat_i) results = learn.train_ens(datasets, clf="LR") for i, result_i in enumerate(results): votes_i = "%s/%d" % (subdirs["votes"], i) raise Exception(result_i.y_pred.dtype) text_i = list(result_i.y_pred.astype(str)) lines = [] for line_j, name_j in zip(text_i, result_i.names): line_j = str(line_j).replace("\n", "") lines.append("%s#%s" % (line_j, name_j)) files.save_txt(lines, votes_i)
def result_exp(prefix, result_dict): lines = [] for info_i, result_i in result_dict.items(): line_i = "%s,%s,%s" % (prefix, info_i, get_metrics(result_i)) lines.append(line_i) files.save_txt(lines, out_path)