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

Updated Qarboost

parent 52f8fc0d
Branches
Tags
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): ...@@ -666,6 +666,7 @@ def get_accuracy_graph(train_accuracies, classifier_name, file_name):
f.savefig(file_name) f.savefig(file_name)
plt.close() plt.close()
class BaseBoost(object): class BaseBoost(object):
def __init__(self): def __init__(self):
...@@ -702,6 +703,8 @@ def getInterpretBase(classifier, directory, classifier_name, weights, ...@@ -702,6 +703,8 @@ def getInterpretBase(classifier, directory, classifier_name, weights,
interpretString += np.array2string(weights[weights_sort], precision=4, separator=',', suppress_small=True) 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, 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) 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_sort) == classifier.n_max_iterations or len(weights) == classifier.n_total_hypotheses_:
if len(weights) == classifier.n_max_iterations: if len(weights) == classifier.n_max_iterations:
interpretString += ", and used all available iterations, " interpretString += ", and used all available iterations, "
......
...@@ -192,7 +192,7 @@ class ColumnGenerationClassifier(BaseEstimator, ClassifierMixin, BaseBoost): ...@@ -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): # 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, # super(CqBoostClassifier, self).__init__(epsilon, n_max_iterations, estimators_generator, dual_constraint_rhs=0,
# save_iteration_as_hyperparameter_each=save_iteration_as_hyperparameter_each) # 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. # # on ne peut pas quitter la boucle principale avec seulement un votant.
# self.mu = mu # self.mu = mu
# self.train_time = 0 # self.train_time = 0
......
...@@ -20,13 +20,13 @@ def randomizedSearch(X_train, y_train, randomState, outputFileName, classifierMo ...@@ -20,13 +20,13 @@ def randomizedSearch(X_train, y_train, randomState, outputFileName, classifierMo
estimator = getattr(classifierModule, CL_type)(randomState) estimator = getattr(classifierModule, CL_type)(randomState)
params_dict = estimator.genDistribs() params_dict = estimator.genDistribs()
if params_dict: if params_dict:
nb_possible_combinations = compute_possible_combinations(params_dict)
metricModule = getattr(Metrics, metric[0]) metricModule = getattr(Metrics, metric[0])
if metric[1] is not None: if metric[1] is not None:
metricKWARGS = dict((index, metricConfig) for index, metricConfig in enumerate(metric[1])) metricKWARGS = dict((index, metricConfig) for index, metricConfig in enumerate(metric[1]))
else: else:
metricKWARGS = {} metricKWARGS = {}
scorer = metricModule.get_scorer(**metricKWARGS) scorer = metricModule.get_scorer(**metricKWARGS)
nb_possible_combinations = compute_possible_combinations(params_dict)
if nIter > nb_possible_combinations: if nIter > nb_possible_combinations:
nIter = nb_possible_combinations nIter = nb_possible_combinations
randomSearch = RandomizedSearchCV(estimator, n_iter=nIter, param_distributions=params_dict, refit=True, 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): ...@@ -16,6 +16,7 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
random_state=random_state, random_state=random_state,
n_estimators=n_estimators, n_estimators=n_estimators,
base_estimator=base_estimator, base_estimator=base_estimator,
algorithm="SAMME"
) )
self.param_names = ["n_estimators", "base_estimator"] self.param_names = ["n_estimators", "base_estimator"]
self.classed_params = ["base_estimator"] self.classed_params = ["base_estimator"]
...@@ -29,8 +30,8 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier): ...@@ -29,8 +30,8 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
def getInterpret(self, directory): def getInterpret(self, directory):
interpretString = "" interpretString = ""
interpretString += self.getFeatureImportance(directory) interpretString += self.getFeatureImportance(directory)
interpretString += "\n\n" interpretString += "\n\n Estimator error | Estimator weight\n"
interpretString += str(self.estimator_errors_) interpretString += "\n".join([str(error) +" | "+ str(weight/sum(self.estimator_weights_)) for error, weight in zip(self.estimator_errors_, self.estimator_weights_)])
return interpretString return interpretString
......
...@@ -79,7 +79,7 @@ class ColumnGenerationClassifierv21(BaseEstimator, ClassifierMixin, BaseBoost): ...@@ -79,7 +79,7 @@ class ColumnGenerationClassifierv21(BaseEstimator, ClassifierMixin, BaseBoost):
self.train_accuracies.append(accuracy_score(y, np.sign(self.previous_vote))) self.train_accuracies.append(accuracy_score(y, np.sign(self.previous_vote)))
continue 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) w = self._solve_two_weights_min_c(new_voter_margin, example_weights)
if w[0] == "break": if w[0] == "break":
self.chosen_columns_.pop() self.chosen_columns_.pop()
......
...@@ -19,7 +19,7 @@ class KNN(KNeighborsClassifier, BaseMonoviewClassifier): ...@@ -19,7 +19,7 @@ class KNN(KNeighborsClassifier, BaseMonoviewClassifier):
) )
self.param_names = ["n_neighbors", "weights", "algorithm", "p"] self.param_names = ["n_neighbors", "weights", "algorithm", "p"]
self.classed_params = [] 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]] ["auto", "ball_tree", "kd_tree", "brute"], [1, 2]]
self.weird_strings = {} self.weird_strings = {}
self.random_state=random_state self.random_state=random_state
......
...@@ -7,10 +7,12 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier): ...@@ -7,10 +7,12 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
def __init__(self, random_state=None, **kwargs): def __init__(self, random_state=None, **kwargs):
super(QarBoost, self).__init__( super(QarBoost, self).__init__(
random_state=random_state, random_state=random_state)
)
self.param_names = [] self.param_names = ["self_complemented", "twice_the_same", "old_fashioned", "previous_vote_weighted",
self.distribs = [] "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.classed_params = []
self.weird_strings = {} self.weird_strings = {}
...@@ -19,6 +21,7 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier): ...@@ -19,6 +21,7 @@ class QarBoost(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
return True return True
def getInterpret(self, directory): def getInterpret(self, directory):
self.getInterpretQar(directory)
return getInterpretBase(self, directory, "QarBoost", self.weights_, self.break_cause) return getInterpretBase(self, directory, "QarBoost", self.weights_, self.break_cause)
......
...@@ -9,7 +9,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier): ...@@ -9,7 +9,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
super(QarBoostNC3, self).__init__( super(QarBoostNC3, self).__init__(
random_state=random_state, random_state=random_state,
self_complemented=False, self_complemented=False,
twice_the_same=True, twice_the_same=False,
previous_vote_weighted=False previous_vote_weighted=False
) )
self.param_names = [] self.param_names = []
...@@ -22,6 +22,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier): ...@@ -22,6 +22,7 @@ class QarBoostNC3(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
return True return True
def getInterpret(self, directory): def getInterpret(self, directory):
self.getInterpretQar(directory)
return getInterpretBase(self, directory, "QarBoostNC3", self.weights_, self.break_cause) return getInterpretBase(self, directory, "QarBoostNC3", self.weights_, self.break_cause)
def get_name_for_fusion(self): def get_name_for_fusion(self):
......
...@@ -9,7 +9,8 @@ class QarBoostv2(ColumnGenerationClassifierQar, BaseMonoviewClassifier): ...@@ -9,7 +9,8 @@ class QarBoostv2(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
super(QarBoostv2, self).__init__( super(QarBoostv2, self).__init__(
random_state=random_state, random_state=random_state,
self_complemented=True, self_complemented=True,
twice_the_same=True twice_the_same=True,
previous_vote_weighted=True
) )
self.param_names = [] self.param_names = []
self.distribs = [] self.distribs = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment