Skip to content
Snippets Groups Projects
Commit e6f9470a authored by Baptiste Bauvin's avatar Baptiste Bauvin
Browse files

Updated Qarboost

parent 52f8fc0d
No related branches found
No related tags found
No related merge requests found
Showing
with 192 additions and 65 deletions
......@@ -666,6 +666,7 @@ def get_accuracy_graph(train_accuracies, classifier_name, file_name):
f.savefig(file_name)
plt.close()
class BaseBoost(object):
def __init__(self):
......@@ -702,6 +703,8 @@ def getInterpretBase(classifier, directory, classifier_name, weights,
interpretString += np.array2string(weights[weights_sort], precision=4, separator=',', suppress_small=True)
interpretString += "\n \t It generated {} columns by attributes and used {} iterations to converge, and selected {} couple(s) of opposed voters".format(classifier.n_stumps,
len(weights_sort), classifier.nb_opposed_voters)
if max(weights) > 0.50:
interpretString += "\n \t The vote is useless in this context : voter n°{} is a dictator of weight > 0.50".format(classifier.chosen_columns_[np.argmax(np.array(weights))])
if len(weights_sort) == classifier.n_max_iterations or len(weights) == classifier.n_total_hypotheses_:
if len(weights) == classifier.n_max_iterations:
interpretString += ", and used all available iterations, "
......
......@@ -192,7 +192,7 @@ class ColumnGenerationClassifier(BaseEstimator, ClassifierMixin, BaseBoost):
# def __init__(self, mu=0.001, epsilon=1e-08, n_max_iterations=None, estimators_generator=None, save_iteration_as_hyperparameter_each=None):
# super(CqBoostClassifier, self).__init__(epsilon, n_max_iterations, estimators_generator, dual_constraint_rhs=0,
# save_iteration_as_hyperparameter_each=save_iteration_as_hyperparameter_each)
# # TODO: Vérifier la valeur de nu (dual_constraint_rhs) à l'initialisation, mais de toute manière ignorée car
# # TODO: Verifier la valeur de nu (dual_constraint_rhs) a l'initialisation, mais de toute maniere ignoree car
# # on ne peut pas quitter la boucle principale avec seulement un votant.
# self.mu = mu
# self.train_time = 0
......
......@@ -20,13 +20,13 @@ def randomizedSearch(X_train, y_train, randomState, outputFileName, classifierMo
estimator = getattr(classifierModule, CL_type)(randomState)
params_dict = estimator.genDistribs()
if params_dict:
nb_possible_combinations = compute_possible_combinations(params_dict)
metricModule = getattr(Metrics, metric[0])
if metric[1] is not None:
metricKWARGS = dict((index, metricConfig) for index, metricConfig in enumerate(metric[1]))
else:
metricKWARGS = {}
scorer = metricModule.get_scorer(**metricKWARGS)
nb_possible_combinations = compute_possible_combinations(params_dict)
if nIter > nb_possible_combinations:
nIter = nb_possible_combinations
randomSearch = RandomizedSearchCV(estimator, n_iter=nIter, param_distributions=params_dict, refit=True,
......
from . import ExecClassifMonoView, MonoviewUtils, analyzeResult
# from . import ExecClassifMonoView, MonoviewUtils, analyzeResult
......@@ -16,6 +16,7 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
random_state=random_state,
n_estimators=n_estimators,
base_estimator=base_estimator,
algorithm="SAMME"
)
self.param_names = ["n_estimators", "base_estimator"]
self.classed_params = ["base_estimator"]
......@@ -29,8 +30,8 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
def getInterpret(self, directory):
interpretString = ""
interpretString += self.getFeatureImportance(directory)
interpretString += "\n\n"
interpretString += str(self.estimator_errors_)
interpretString += "\n\n Estimator error | Estimator weight\n"
interpretString += "\n".join([str(error) +" | "+ str(weight/sum(self.estimator_weights_)) for error, weight in zip(self.estimator_errors_, self.estimator_weights_)])
return interpretString
......
......@@ -79,7 +79,7 @@ class ColumnGenerationClassifierv21(BaseEstimator, ClassifierMixin, BaseBoost):
self.train_accuracies.append(accuracy_score(y, np.sign(self.previous_vote)))
continue
# ---- On résoud le problème à deux votants analytiquement.
# ---- On resoud le probleme a deux votants analytiquement.
w = self._solve_two_weights_min_c(new_voter_margin, example_weights)
if w[0] == "break":
self.chosen_columns_.pop()
......
......@@ -19,7 +19,7 @@ class KNN(KNeighborsClassifier, BaseMonoviewClassifier):
)
self.param_names = ["n_neighbors", "weights", "algorithm", "p"]
self.classed_params = []
self.distribs = [CustomRandint(low=1, high=20), ["uniform", "distance"],
self.distribs = [CustomRandint(low=1, high=10), ["uniform", "distance"],
["auto", "ball_tree", "kd_tree", "brute"], [1, 2]]
self.weird_strings = {}
self.random_state=random_state
......
......@@ -7,10 +7,12 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
def __init__(self, random_state=None, **kwargs):
super(QarBoost, self).__init__(
random_state=random_state,
)
self.param_names = []
self.distribs = []
random_state=random_state)
self.param_names = ["self_complemented", "twice_the_same", "old_fashioned", "previous_vote_weighted",
"c_bound_choice", "random_start", "two_wieghts_problem"]
self.distribs = [[True, False], [True, False], [True, False], [True, False],
[True, False], [True, False], [True, False]]
self.classed_params = []
self.weird_strings = {}
......@@ -19,6 +21,7 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
return True
def getInterpret(self, directory):
self.getInterpretQar(directory)
return getInterpretBase(self, directory, "QarBoost", self.weights_, self.break_cause)
......
......@@ -9,7 +9,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
super(QarBoostNC3, self).__init__(
random_state=random_state,
self_complemented=False,
twice_the_same=True,
twice_the_same=False,
previous_vote_weighted=False
)
self.param_names = []
......@@ -22,6 +22,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
return True
def getInterpret(self, directory):
self.getInterpretQar(directory)
return getInterpretBase(self, directory, "QarBoostNC3", self.weights_, self.break_cause)
def get_name_for_fusion(self):
......
......@@ -9,7 +9,8 @@ class QarBoostv2(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
super(QarBoostv2, self).__init__(
random_state=random_state,
self_complemented=True,
twice_the_same=True
twice_the_same=True,
previous_vote_weighted=True
)
self.param_names = []
self.distribs = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment