Exemplo n.º 1
0
def find_weights(datasets):
	results=validation_votes(datasets)
	loss_fun=LossFunction(ens.Votes(results))
	bound_w = [(0.0, 1.0)  for _ in datasets]
	result = differential_evolution(loss_fun, bound_w, maxiter=1000, tol=1e-7)
	weights=result['x']
	return weights
Exemplo n.º 2
0
def diff_voting(common,deep,clf="LR"):
	datasets=ens.read_dataset(common,deep)
	weights=find_weights(datasets)
	results=learn.train_ens(datasets,clf="LR")
	votes=ens.Votes(results)
	result=votes.weighted(weights)
	return result
Exemplo n.º 3
0
def cv_exp(common, binary, out_path=None, clf="LR"):
    datasets = ens.read_dataset(common, binary)
    validation = [CrossVal(0.1 * (i + 1)) for i in range(2, 10)]
    result_dict = {}
    for valid_i in validation:
        votes_i = ens.Votes(valid_i(datasets, clf)[1])
        result_dict[str(valid_i)] = votes_i.voting(False)
    exp.result_exp("no weights", result_dict, out_path)
Exemplo n.º 4
0
def rename_frames(paths, json_path):
    datasets = ens.read_dataset(paths["common"], paths["binary"])
    helper = get_renam_fun(json_path)
    if (get_fun):
        return helper
    new_datasets = datasets  #[helper(data_i) for data_i in datasets]
    votes = ens.Votes(learn.train_ens(new_datasets, clf="LR"))
    result_i = votes.voting(False)
    result_i.report()
Exemplo n.º 5
0
 def __call__(self, datasets, clf="LR"):
     acc, pairs = [], []
     for i in range(self.k):
         self.base_val.reset()
         pair_i = self.base_val(datasets, clf)
         result_i = ens.Votes(pair_i[1]).voting(False)
         acc.append(result_i.get_acc())
         pairs.append(pair_i)
     mediana = np.argsort(acc)[len(acc) // 2]
     return pairs[mediana]
Exemplo n.º 6
0
def full_train(common, binary, clf):
    datasets = ens.read_dataset(common, binary)
    results = []
    for data_i in datasets:
        train, test = data_i.split()
        model = learn.make_model(train, clf)
        X_train, y_true = train.get_X(), train.get_labels()
        y_pred = model.predict_proba(X_train)
        result_i = learn.Result(y_true, y_pred, test.names())
        results.append(result_i)
    return ens.Votes(results)
Exemplo n.º 7
0
def ensemble(paths, system=None, clf="LR", s_clf=None, transform=None):
    datasets = ens.read_dataset(paths["common"], paths["binary"])
    if (transform):
        datasets = [transform(data_i) for data_i in datasets]
    results = [
        learn.train_model(data_i, clf_type=clf, binary=False)
        for data_i in datasets
    ]
    if (s_clf):
        results = [results[clf_i] for clf_i in s_clf]
    votes = ens.Votes(results)
    return voting(votes, system)
Exemplo n.º 8
0
 def helper(common_path, binary_path, clf="LR"):
     datasets = ens.read_dataset(common_path, binary_path)
     results = [person_acc(data_i) for data_i in datasets]
     return ens.Votes(results)
Exemplo n.º 9
0
 def single_optim(self,datasets,results,clf):
     weights=self.find_weights(results)
     results=learn.train_ens(datasets,clf)
     votes=ens.Votes(results)
     result=votes.weighted(weights)
     return result,weights
Exemplo n.º 10
0
 def __init__(self,all_votes):
     self.all_votes=ens.Votes(all_votes)
     self.iter=0
Exemplo n.º 11
0
def test_weights(datasets, clf, weights):
    votes = ens.Votes(learn.train_ens(datasets, clf))
    return votes.weighted(weights)
Exemplo n.º 12
0
def get_votes(train, clf, names, selector_gen):
    all_votes = []
    for selector_i in selector_gen(names):
        results = learn.train_ens(train, clf=clf, selector=selector_i)
        all_votes.append(ens.Votes(results))
    return all_votes
Exemplo n.º 13
0
 def __init__(self, all_votes):
     self.all_votes = ens.Votes(all_votes)
     self.d = [result_i.true_one_hot() for result_i in all_votes]
Exemplo n.º 14
0
	def helper(size):
		ind_i= random.sample(indexes,size)
		subset_i=[votes.results[k] for k in ind_i]
		votes_i=ens.Votes(subset_i)
		result_i=votes_i.voting(False)
		return result_i.get_acc(),ind_i
Exemplo n.º 15
0
def base_train(common, binary, clf):
    datasets = ens.read_dataset(common, binary)
    results = learn.train_ens(datasets, clf=clf)
    return ens.Votes(results)
Exemplo n.º 16
0
def score_dataset(results, score_weights):
    pref = [as_pref(result_i, score_weights) for result_i in results]
    y_true, names = results[0].y_true, results[0].names
    results = [learn.Result(y_true, pref_i, names) for pref_i in pref]
    return ens.Votes(results)