Skip to content
Snippets Groups Projects
Commit 4987570c authored by Dominique Benielli's avatar Dominique Benielli
Browse files

some doc

parent 66282b7b
No related branches found
No related tags found
No related merge requests found
Pipeline #3434 passed
Showing
with 622 additions and 29 deletions
......@@ -8,7 +8,31 @@ from ..monoview.monoview_utils import BaseMonoviewClassifier, CustomUniform
classifier_class_name = "MinCQGraalpy"
class MinCQGraalpy(RegularizedBinaryMinCqClassifier, BaseMonoviewClassifier):
"""
Parameters
----------
random_state
mu
self_complemented
n_stumps_per_attribute
kwargs
Attributes
----------
param_names
distribs
n_stumps_per_attribute
classed_params
weird_strings
nbCores
"""
def __init__(self, random_state=None, mu=0.01, self_complemented=True,
n_stumps_per_attribute=1, **kwargs):
super(MinCQGraalpy, self).__init__(mu=mu,
......@@ -29,20 +53,59 @@ class MinCQGraalpy(RegularizedBinaryMinCqClassifier, BaseMonoviewClassifier):
self.nbCores = kwargs["nbCores"]
def canProbas(self):
"""Used to know if the classifier can return label probabilities"""
"""
Used to know if the classifier can return label probabilities
Returns
-------
False
"""
return False
def set_params(self, **params):
"""
set parameter 'self.mu', 'self.random_state
'self.n_stumps_per_attribute
Parameters
----------
params
Returns
-------
self : object
Returns self.
"""
self.mu = params["mu"]
self.random_state = params["random_state"]
self.n_stumps_per_attribute = params["n_stumps_per_attribute"]
return self
def get_params(self, deep=True):
"""
Parameters
----------
deep : bool (default : true) not used
Returns
-------
dictianary with "random_state", "mu", "n_stumps_per_attribute"
"""
return {"random_state": self.random_state, "mu": self.mu,
"n_stumps_per_attribute": self.n_stumps_per_attribute}
def getInterpret(self, directory, y_test):
"""
Parameters
----------
directory
y_test
Returns
-------
string of interpret_string
"""
interpret_string = "Cbound on train :" + str(self.train_cbound)
np.savetxt(directory + "times.csv", np.array([self.train_time, 0]))
# interpret_string += "Train C_bound value : "+str(self.cbound_train)
......
......@@ -8,9 +8,21 @@ classifier_class_name = "MinCQGraalpyTree"
class MinCQGraalpyTree(RegularizedBinaryMinCqClassifier,
BaseMonoviewClassifier):
"""
Parameters
----------
random_state
mu
self_complemented
n_stumps_per_attribute
max_depth
kwargs
"""
def __init__(self, random_state=None, mu=0.01, self_complemented=True,
n_stumps_per_attribute=1, max_depth=2, **kwargs):
super(MinCQGraalpyTree, self).__init__(mu=mu,
estimators_generator=TreeClassifiersGenerator(
n_trees=n_stumps_per_attribute,
......
......@@ -10,9 +10,43 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "RandomForest"
class RandomForest(RandomForestClassifier, BaseMonoviewClassifier):
"""RandomForest Classifier Class
Parameters
----------
random_state
n_estimators
max_depth : int maximum of depth (default : 10)
criterion : criteria (default : 'gini')
kwargs
Attributes
----------
param_names
distribs
classed_params
weird_strings
"""
def __init__(self, random_state=None, n_estimators=10,
max_depth=None, criterion='gini', **kwargs):
"""
Parameters
----------
random_state
n_estimators
max_depth
criterion
kwargs
"""
super(RandomForest, self).__init__(
n_estimators=n_estimators,
max_depth=max_depth,
......@@ -28,13 +62,29 @@ class RandomForest(RandomForestClassifier, BaseMonoviewClassifier):
self.weird_strings = {}
def canProbas(self):
"""Used to know if the classifier can return label probabilities"""
"""Used to know if the classifier can return label probabilities
Returns
-------
True
"""
return True
def getInterpret(self, directory, y_test):
interpretString = ""
interpretString += self.getFeatureImportance(directory)
return interpretString
"""
Parameters
----------
directory
y_test
Returns
-------
string for interpretation interpret_string
"""
interpret_string = ""
interpret_string += self.getFeatureImportance(directory)
return interpret_string
# def formatCmdArgs(args):
......
......@@ -44,9 +44,41 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SCM"
class SCM(scm, BaseMonoviewClassifier):
"""
SCM Classifier
Parameters
----------
random_state (default : None)
model_type : string (default: "conjunction")
max_rules : int number maximum of rules (default : 10)
p : float value(default : 0.1 )
kwarg : others arguments
Attributes
----------
param_names
distribs
classed_params
weird_strings
"""
def __init__(self, random_state=None, model_type="conjunction",
max_rules=10, p=0.1, **kwargs):
"""
Parameters
----------
random_state
model_type
max_rules
p
kwargs
"""
super(SCM, self).__init__(
random_state=random_state,
model_type=model_type,
......@@ -61,7 +93,13 @@ class SCM(scm, BaseMonoviewClassifier):
self.weird_strings = {}
def canProbas(self):
"""Used to know if the classifier can return label probabilities"""
"""
Used to know if the classifier can return label probabilities
Returns
-------
return False in any case
"""
return False
def getInterpret(self, directory, y_test):
......
......@@ -14,7 +14,32 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SCMPregen"
class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
"""
Parameters
----------
random_state
model_type
max_rules
p
n_stumps
self_complemented
estimators_generator
max_depth
kwargs
Attributes
----------
param_names
distribs
classed_params
weird_strings
self_complemented
n_stumps
estimators_generator
max_depth
"""
def __init__(self, random_state=None, model_type="conjunction",
max_rules=10, p=0.1, n_stumps=10, self_complemented=True,
estimators_generator="Stumps", max_depth=1, **kwargs):
......@@ -39,13 +64,46 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
self.max_depth=1
def get_params(self, deep=True):
"""
Parameters
----------
deep : boolean (default : True) not used
Returns
-------
parame
"""
params = super(SCMPregen, self).get_params(deep)
params["estimators_generator"] = self.estimators_generator
params["max_depth"] = self.max_depth
params["n_stumps"] = self.n_stumps
return params
def fit(self, X, y, tiebreaker=None, iteration_callback=None, **fit_params):
def fit(self, X, y, tiebreaker=None, iteration_callback=None,
**fit_params):
"""
fit function
Parameters
----------
X {array-like, sparse matrix}, shape (n_samples, n_features)
For kernel="precomputed", the expected shape of X is
(n_samples_test, n_samples_train).
y : { array-like, shape (n_samples,)
Target values class labels in classification
tiebreaker
iteration_callback : (default : None)
fit_params : others parameters
Returns
-------
self : object
Returns self.
"""
pregen_X, _ = self.pregen_voters(X, y)
list_files = os.listdir(".")
a = int(self.random_state.randint(0, 10000))
......@@ -66,6 +124,20 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
return self
def predict(self, X):
"""
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training vectors, where n_samples is the number of samples
and n_features is the number of features.
For kernel="precomputed", the expected shape of X is
(n_samples, n_samples).
Returns
-------
y_pred : array, shape (n_samples,)
"""
pregen_X, _ = self.pregen_voters(X)
list_files = os.listdir(".")
a = int(self.random_state.randint(0, 10000))
......@@ -83,12 +155,29 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
return self.classes_[self.model_.predict(place_holder)]
def canProbas(self):
"""Used to know if the classifier can return label probabilities"""
"""
Used to know if the classifier can return label probabilities
Returns
-------
False in any case
"""
return False
def getInterpret(self, directory, y_test):
interpretString = "Model used : " + str(self.model_)
return interpretString
"""
Parameters
----------
directory
y_test
Returns
-------
interpret_string string of interpretation
"""
interpret_string = "Model used : " + str(self.model_)
return interpret_string
# def formatCmdArgs(args):
......
......@@ -9,9 +9,19 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SGD"
class SGD(SGDClassifier, BaseMonoviewClassifier):
"""
Parameters
----------
random_state
loss
penalty
alpha
kwargs
"""
def __init__(self, random_state=None, loss='hinge',
penalty='l2', alpha=0.0001, **kwargs):
super(SGD, self).__init__(
loss=loss,
penalty=penalty,
......@@ -26,12 +36,31 @@ class SGD(SGDClassifier, BaseMonoviewClassifier):
self.weird_strings = {}
def canProbas(self):
"""Used to know if the classifier can return label probabilities"""
"""
Used to know if the classifier can return label probabilities
Returns
-------
return True in all case
"""
return True
def getInterpret(self, directory, y_test):
interpretString = ""
return interpretString
"""
Parameters
----------
directory
y_test
Returns
-------
interpret_string str to interpreted
"""
interpret_string = ""
return interpret_string
# def formatCmdArgs(args):
......
......@@ -9,8 +9,17 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SVMLinear"
class SVMLinear(SVCClassifier, BaseMonoviewClassifier):
"""SVMLinear
Parameters
----------
random_state
C
kwargs
"""
def __init__(self, random_state=None, C=1.0, **kwargs):
super(SVMLinear, self).__init__(
C=C,
kernel='linear',
......
......@@ -9,8 +9,28 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SVMPoly"
class SVMPoly(SVCClassifier, BaseMonoviewClassifier):
"""
Class of SVMPoly for SVC Classifier
Parameters
----------
random_state
C
degree
kwargs
Attributes
----------
param_names : list of parameters names
distribs : list of random_state distribution
"""
def __init__(self, random_state=None, C=1.0, degree=3, **kwargs):
super(SVMPoly, self).__init__(
C=C,
kernel='poly',
......
......@@ -9,8 +9,24 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "SVMRBF"
class SVMRBF(SVCClassifier, BaseMonoviewClassifier):
"""
class SVMRBF for classifier SVCC
Parameters
----------
random_state
C
kwargs
Attributes
----------
param_names : list of parameters names
distribs : list of random_state distribution
"""
def __init__(self, random_state=None, C=1.0, **kwargs):
super(SVMRBF, self).__init__(
C=C,
kernel='rbf',
......@@ -27,6 +43,18 @@ class SVMRBF(SVCClassifier, BaseMonoviewClassifier):
def paramsToSet(nIter, randomState):
"""
Parameters
----------
nIter : int number of iterations
randomState :
Returns
-------
paramsSet list of parameters dictionary with key "C"
"""
paramsSet = []
for _ in range(nIter):
paramsSet.append({"C": randomState.randint(1, 10000), })
......
......@@ -6,26 +6,60 @@ __status__ = "Prototype" # Production, Development, Prototype
def printMetricScore(metricScores, metric_list):
metricScoreString = "\n\n"
"""
this function print the metrics scores
Parameters
----------
metricScores : the score of metrics
metric_list : list of metrics
Returns
-------
metric_score_string string constaining all metric results
"""
metric_score_string = "\n\n"
for metric in metric_list:
metricModule = getattr(metrics, metric[0])
metric_module = getattr(metrics, metric[0])
if metric[1] is not None:
metricKWARGS = dict((index, metricConfig) for index, metricConfig in
metric_kwargs = dict((index, metricConfig) for index, metricConfig in
enumerate(metric[1]))
else:
metricKWARGS = {}
metricScoreString += "\tFor " + metricModule.getConfig(
**metricKWARGS) + " : "
metricScoreString += "\n\t\t- Score on train : " + str(
metric_kwargs = {}
metric_score_string += "\tFor " + metric_module.getConfig(
**metric_kwargs) + " : "
metric_score_string += "\n\t\t- Score on train : " + str(
metricScores[metric[0]][0])
metricScoreString += "\n\t\t- Score on test : " + str(
metric_score_string += "\n\t\t- Score on test : " + str(
metricScores[metric[0]][1])
metricScoreString += "\n\n"
return metricScoreString
metric_score_string += "\n\n"
return metric_score_string
def getTotalMetricScores(metric, trainLabels, testLabels, validationIndices,
learningIndices, labels):
"""
Parameters
----------
metric :
trainLabels : labels of train
testLabels : labels of test
validationIndices :
learningIndices :
labels :
Returns
-------
list of [trainScore, testScore]
"""
metricModule = getattr(metrics, metric[0])
if metric[1] is not None:
metricKWARGS = dict((index, metricConfig) for index, metricConfig in
......@@ -63,6 +97,52 @@ def execute(classifier, trainLabels,
name, KFolds,
hyper_param_search, nIter, metric_list,
views_indices, random_state, labels, classifierModule):
"""
Parameters
----------
classifier : classifier used
trainLabels : labels of train
testLabels : labels of test
DATASET :
classificationKWARGS
classificationIndices
labels_dictionary
views
nbCores
times
name
KFolds
hyper_param_search
nIter
metric_list
views_indices
random_state
labels
classifierModule
Returns
-------
retuern tuple of (stringAnalysis, imagesAnalysis, metricsScore)
"""
classifier_name = classifier.short_name
learningIndices, validationIndices, testIndicesMulticlass = classificationIndices
......
......@@ -18,9 +18,33 @@ __author__ = "Baptiste Bauvin"
__status__ = "Prototype" # Production, Development, Prototype
def init_constants(kwargs, classification_indices, metrics, name, nb_cores, k_folds,
def init_constants(kwargs, classification_indices, metrics,
name, nb_cores, k_folds,
dataset_var):
"""Used to init the constants"""
"""
Used to init the constants
Parameters
----------
kwargs :
classification_indices :
metrics :
name :
nb_cores : nint number of cares to execute
k_folds :
dataset_var : {array-like} shape (n_samples, n_features)
dataset variable
Returns
-------
tuple of (classifier_name, t_start, views_indices,
classifier_config, views, learning_rate)
"""
views = kwargs["view_names"]
views_indices = kwargs["view_indices"]
if not metrics:
......@@ -39,12 +63,40 @@ def init_constants(kwargs, classification_indices, metrics, name, nb_cores, k_fo
for view_index, view_name in zip(views_indices, views):
logging.info("Info:\t Shape of " + str(view_name) + " :" + str(
dataset_var.get_shape()))
return classifier_name, t_start, views_indices, classifier_config, views, learning_rate
return classifier_name, t_start, views_indices,\
classifier_config, views, learning_rate
def save_results(classifier, labels_dictionary, string_analysis, views, classifier_module,
classification_kargs, directory, learning_rate, name,
images_analysis):
"""
Save results in derectory
Parameters
----------
classifier : classifier class
labels_dictionary : dict dictionary of labels
string_analysis : str
views :
classifier_module : module of the classifier
classification_kargs :
directory : str directory
learning_rate :
name :
images_analysis :
"""
labels_set = set(labels_dictionary.values())
logging.info(string_analysis)
views_string = "-".join(views)
......@@ -83,6 +135,52 @@ def exec_multiview_multicore(directory, core_index, name, learning_rate, nb_fold
random_state, labels,
hyper_param_search=False, nb_cores=1, metrics=None,
n_iter=30, **arguments):
"""
execute multiview process on
Parameters
----------
directory : indicate the directory
core_index :
name : name of the data file to perform
learning_rate :
nb_folds :
database_type :
path : path to the data name
labels_dictionary
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
labels :
hyper_param_search :
nb_cores : in number of cores
metrics : metric to use
n_iter : int number of iterations
arguments : others arguments
Returns
-------
exec_multiview on directory, dataset_var, name, learning_rate, nb_folds, 1,
database_type, path, labels_dictionary,
random_state, labels,
hyper_param_search=hyper_param_search, metrics=metrics,
n_iter=n_iter, **arguments
"""
"""Used to load an HDF5 dataset_var for each parallel job and execute multiview classification"""
dataset_var = h5py.File(path + name + str(core_index) + ".hdf5", "r")
return exec_multiview(directory, dataset_var, name, learning_rate, nb_folds, 1,
......@@ -96,7 +194,50 @@ def exec_multiview(directory, dataset_var, name, classification_indices, k_folds
nb_cores, database_type, path,
labels_dictionary, random_state, labels,
hyper_param_search=False, metrics=None, n_iter=30, **kwargs):
"""Used to execute multiview classification and result analysis"""
"""Used to execute multiview classification and result analysis
Parameters
----------
directory : indicate the directory
dataset_var :
name
classification_indices
k_folds
nb_cores
database_type
path
labels_dictionary : dict dictionary of labels
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
labels
hyper_param_search
metrics
n_iter : int number of iterations
kwargs
Returns
-------
``MultiviewResult``
"""
logging.debug("Start:\t Initialize constants")
cl_type, \
t_start, \
......
......@@ -28,13 +28,34 @@ def get_names(classed_list):
class BaseMultiviewClassifier(BaseEstimator, ClassifierMixin):
"""
BaseMultiviewClassifier base of Multiview classifiers
Parameters
----------
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
"""
def __init__(self, random_state):
self.random_state = random_state
self.short_name = self.__class__.__name__
self.weird_strings = {}
def genBestParams(self, detector):
def gen_best_params(self, detector):
"""
return best parameters of detector
Parameters
----------
detector :
Returns
-------
best param : dictionary with param name as key and best parameters
value
"""
return dict((param_name, detector.best_params_[param_name])
for param_name in self.param_names)
......
......@@ -15,10 +15,23 @@ classifier_class_name = "WeightedLinearEarlyFusion"
class WeightedLinearEarlyFusion(BaseMultiviewClassifier, BaseFusionClassifier):
"""
WeightedLinearEarlyFusion
Parameters
----------
random_state
view_weights
monoview_classifier_name
monoview_classifier_config
Attributes
----------
"""
def __init__(self, random_state=None, view_weights=None,
monoview_classifier_name="decision_tree",
monoview_classifier_config={}):
super(WeightedLinearEarlyFusion, self).__init__(random_state=random_state)
self.view_weights = view_weights
self.monoview_classifier_name = monoview_classifier_name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment