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

doc string

parent 4987570c
No related branches found
No related tags found
No related merge requests found
Showing
with 549 additions and 46 deletions
......@@ -18,12 +18,35 @@ __status__ = "Prototype" # Production, Development, Prototype
# __date__ = 2016 - 03 - 25
def change_label_to_minus(y):
"""
Change the label 0 to minus one
Parameters
----------
y :
Returns
-------
label y with -1 instead of 0
"""
minus_y = np.copy(y)
minus_y[np.where(y == 0)] = -1
return minus_y
def change_label_to_zero(y):
"""
Change the label -1 to 0
Parameters
----------
y
Returns
-------
"""
zeroed_y = np.copy(y)
zeroed_y[np.where(y == -1)] = 0
return zeroed_y
......
......@@ -17,12 +17,44 @@ classifier_class_name = "Adaboost"
class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
"""
This class implement a Classifier with adaboost algorithm.
This class implement a Classifier with adaboost algorithm inherit from sklearn
AdaBoostClassifier
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.
n_estimators : int number of estimators
base_estimator :
kwargs : others arguments
Attributes
----------
param_name :
classed_params :
distribs :
weird_strings :
plotted_metric : selection of metric to plot
plotted_metric_name : name of the metric to plot
step_predictions :
"""
def __init__(self, random_state=None, n_estimators=50,
base_estimator=None, **kwargs):
super(Adaboost, self).__init__(
random_state=random_state,
n_estimators=n_estimators,
......@@ -39,6 +71,23 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
self.step_predictions = None
def fit(self, X, y, sample_weight=None):
"""
Fit adaboost model
Parameters
----------
X : {array-like, sparse matrix}, shape (n_samples, n_features)
y : { array-like, shape (n_samples,)
Target values class labels in classification
sample_weight :
Returns
-------
self : object
Returns self.
"""
begin = time.time()
super(Adaboost, self).fit(X, y, sample_weight=sample_weight)
end = time.time()
......@@ -51,10 +100,31 @@ class Adaboost(AdaBoostClassifier, BaseMonoviewClassifier):
return self
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 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
-------
predictions : ndarray of shape (n_samples, )
The estimated labels.
"""
begin = time.time()
pred = super(Adaboost, self).predict(X)
end = time.time()
......
......@@ -15,6 +15,26 @@ classifier_class_name = "AdaboostGraalpy"
class AdaBoostGP(BaseEstimator, ClassifierMixin, BaseBoost):
"""Scikit-Learn compatible AdaBoost classifier. Original code by Pascal Germain, adapted by Jean-Francis Roy.
Parameters
----------
n_iterations : int, optional
The number of iterations of the algorithm. Defaults to 200.
iterations_to_collect_as_hyperparameters : list
Iteration numbers to collect while learning, that will be converted as hyperparameter values at evaluation time.
Defaults to None.
classifiers_generator : Transformer, optional
A transformer to convert input samples in voters' outputs. Default: Decision stumps transformer, with 10 stumps
per attributes.
callback_function : function, optional
A function to call at each iteration that is supplied learning information. Defaults to None.
n_stumps : int ( default : 10)
self_complemented : boolean (default : True
Attributes
----------
n_iterations : int, optional
......@@ -34,6 +54,7 @@ class AdaBoostGP(BaseEstimator, ClassifierMixin, BaseBoost):
iterations_to_collect_as_hyperparameters=True,
classifiers_generator=None, callback_function=None,
n_stumps=10, self_complemented=True):
self.n_iterations = n_iterations
self.n_stumps = n_stumps
self.iterations_to_collect_as_hyperparameters = iterations_to_collect_as_hyperparameters
......@@ -158,9 +179,37 @@ class AdaBoostGP(BaseEstimator, ClassifierMixin, BaseBoost):
class AdaboostGraalpy(AdaBoostGP, BaseMonoviewClassifier):
"""AdaboostGraalpy
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.
n_iterations : in number of iterations (default : 200)
n_stumps : int (default 1)
kwargs : others arguments
Attributes
----------
param_names :
distribs :
weird_strings :
n_stumps :
nbCores :
"""
def __init__(self, random_state=None, n_iterations=200, n_stumps=1,
**kwargs):
super(AdaboostGraalpy, self).__init__(
n_iterations=n_iterations,
n_stumps=n_stumps
......@@ -177,10 +226,28 @@ class AdaboostGraalpy(AdaBoostGP, 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
-------
True in any case
"""
return True
def getInterpret(self, directory, y_test):
"""
Parameters
----------
directory :
y_test :
Returns
-------
retur string of interpret
"""
np.savetxt(directory + "train_metrics.csv", self.losses, delimiter=',')
np.savetxt(directory + "y_test_step.csv", self.test_preds,
delimiter=',')
......
......@@ -19,7 +19,55 @@ classifier_class_name = "AdaboostPregen"
class AdaboostPregen(AdaBoostClassifier, BaseMonoviewClassifier,
PregenClassifier):
"""
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.
n_estimators : int number of estimators (default : 50)
base_estimator :
n_stumps : int (default : 1)
estimators_generator : str, (default : "Stumps")
max_depth : int (default : 1)
self_complemeted : bool, (default : True)
kwargs : others arguments
Attributes
----------
param_names : list of parameters names
classed_params : list of parameters names
distribs :
weird_strings :
plotted_metric
plotted_metric_name : str name of plotted metric
step_predictions :
estimators_generator :
max_depth :
n_stumps :
self_complemented :
"""
def __init__(self, random_state=None, n_estimators=50,
base_estimator=None, n_stumps=1, estimators_generator="Stumps",
max_depth=1, self_complemeted=True,
......@@ -48,6 +96,21 @@ class AdaboostPregen(AdaBoostClassifier, BaseMonoviewClassifier,
self.self_complemented = self_complemeted
def fit(self, X, y, sample_weight=None):
"""
Fit the AdaboostPregen
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
sample_weight :
"""
begin = time.time()
pregen_X, pregen_y = self.pregen_voters(X, y)
super(AdaboostPregen, self).fit(pregen_X, pregen_y,
......@@ -68,10 +131,29 @@ class AdaboostPregen(AdaBoostClassifier, BaseMonoviewClassifier,
range(self.estimator_errors_.shape[0])])
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 predict(self, X):
"""
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).
Returns
-------
"""
begin = time.time()
pregen_X, _ = self.pregen_voters(X)
pred = super(AdaboostPregen, self).predict(pregen_X)
......
......@@ -5,9 +5,34 @@ from ..monoview.monoview_utils import BaseMonoviewClassifier, CustomRandint
classifier_class_name = "CBBoost"
class CBBoost(CBBoostClassifier, BaseMonoviewClassifier):
"""
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.
n_max_iterations :
n_stumps :
kwargs : others arguments
Attributes
----------
param_names : names of parameter used for hyper parameter search
distribs :
classed_params :
weird_strings :
"""
def __init__(self, random_state=None, n_max_iterations=500, n_stumps=1,
**kwargs):
super(CBBoost, self).__init__(n_max_iterations=n_max_iterations,
random_state=random_state,
self_complemented=True,
......@@ -25,13 +50,39 @@ class CBBoost(CBBoostClassifier, 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):
"""
return interpretation string
Parameters
----------
directory :
y_test :
Returns
-------
"""
return self.getInterpretCBBoost(directory, y_test)
def get_name_for_fusion(self):
"""
Returns
-------
string name of fusion
"""
return "CBB"
......
......@@ -5,10 +5,23 @@ from ..monoview.monoview_utils import BaseMonoviewClassifier, CustomRandint
classifier_class_name = "CGDesc"
class CGDesc(ColumnGenerationClassifierQar, BaseMonoviewClassifier):
"""
Parameters
----------
random_state
n_max_iterations
n_stumps
estimators_generator
twice_the_same
max_depth
kwargs
"""
def __init__(self, random_state=None, n_max_iterations=500, n_stumps=1,
estimators_generator="Stumps", twice_the_same=True, max_depth=1,
**kwargs):
super(CGDesc, self).__init__(n_max_iterations=n_max_iterations,
random_state=random_state,
self_complemented=True,
......
......@@ -11,9 +11,22 @@ classifier_class_name = "KNN"
class KNN(KNeighborsClassifier, BaseMonoviewClassifier):
"""
Implement extention of KNeighborsClassifier of sklearn
for the usage of the multiview_platform.
Parameters
----------
random_state
n_neighbors
weights
algorithm
p
kwargs
"""
def __init__(self, random_state=None, n_neighbors=5,
weights='uniform', algorithm='auto', p=2, **kwargs):
super(KNN, self).__init__(
n_neighbors=n_neighbors,
weights=weights,
......
......@@ -12,9 +12,42 @@ __status__ = "Prototype" # Production, Development, Prototype
classifier_class_name = "Lasso"
class Lasso(LassoSK, BaseMonoviewClassifier):
"""
Parameters
----------
random_state :
alpha : float, optional
Constant that multiplies the L1 term. Defaults to 1.0.
``alpha = 0`` is equivalent to an ordinary least square, solved
by the :class:`LinearRegression` object. For numerical
reasons, using ``alpha = 0`` is with the Lasso object is
not advised
and you should prefer the LinearRegression object. (default( : 10)
max_iter : int The maximum number of iterations (default : 10)
warm_start : bool, optional
When set to True, reuse the solution of the previous call to fit as
initialization, otherwise, just erase the previous solution.
kwargs : others arguments
Attributes
----------
param_name :
classed_params :
distribs :
weird_strings :
"""
def __init__(self, random_state=None, alpha=1.0,
max_iter=10, warm_start=False, **kwargs):
super(Lasso, self).__init__(
alpha=alpha,
max_iter=max_iter,
......@@ -40,12 +73,31 @@ class Lasso(LassoSK, BaseMonoviewClassifier):
return signed
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 getInterpret(self, directory, y_test):
interpretString = ""
return interpretString
"""
return the interpreted string
Parameters
----------
directory :
y_test :
Returns
-------
interpreted string, str interpret_string
"""
interpret_string = ""
return interpret_string
# def formatCmdArgs(args):
......
......@@ -444,6 +444,13 @@ class DecisionStumpVoter(Voter):
direction : int (-1 or 1)
Used to reverse classification decision
Attributes
----------
attribute_index :
threshold :
direction :
"""
def __init__(self, attribute_index, threshold, direction=1):
......@@ -508,6 +515,19 @@ class StumpsVotersGenerator(VotersGenerator):
def generate(self, X, y=None, self_complemented=False,
only_complements=False):
"""
Parameters
----------
X
y
self_complemented
only_complements
Returns
-------
"""
voters = []
if len(X) != 0:
for i in range(len(X[0])):
......
......@@ -9,14 +9,22 @@ classifier_class_name = "MinCQGraalpy"
class MinCQGraalpy(RegularizedBinaryMinCqClassifier, BaseMonoviewClassifier):
"""
MinCQGraalpy extend of ``RegularizedBinaryMinCqClassifier ``
Parameters
----------
random_state
mu
self_complemented
n_stumps_per_attribute
kwargs
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
mu : float, (default: 0.01)
self_complemented : bool (default : True)
n_stumps_per_attribute : (default: =1
kwargs : others arguments
Attributes
----------
......@@ -30,7 +38,7 @@ class MinCQGraalpy(RegularizedBinaryMinCqClassifier, BaseMonoviewClassifier):
weird_strings
nbCores
nbCores : number of cores
"""
def __init__(self, random_state=None, mu=0.01, self_complemented=True,
......
......@@ -12,13 +12,35 @@ class MinCQGraalpyTree(RegularizedBinaryMinCqClassifier,
Parameters
----------
random_state
mu
self_complemented
n_stumps_per_attribute
max_depth
kwargs
random_state :
mu : (default : 0.01)
self_complemented : ( default : True)
n_stumps_per_attribute : int ( default : 1)
max_depth :
kwargs : others parameters
Attributes
----------
param_name :
distribs :
classed_params :
n_stumps_per_attribute : int
weird_strings :
max_depth :
random_state :
nbCores :
"""
def __init__(self, random_state=None, mu=0.01, self_complemented=True,
n_stumps_per_attribute=1, max_depth=2, **kwargs):
......@@ -44,10 +66,28 @@ class MinCQGraalpyTree(RegularizedBinaryMinCqClassifier,
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
-------
True
"""
return True
def set_params(self, **params):
"""
set parameter in the input dictionary
Parameters
----------
params : dict parameter to set
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"]
......@@ -55,11 +95,35 @@ class MinCQGraalpyTree(RegularizedBinaryMinCqClassifier,
return self
def get_params(self, deep=True):
"""
get parameter
Parameters
----------
deep : (boolean (default : True) not used
Returns
-------
dictionary of parameter as key and its values
"""
return {"random_state": self.random_state, "mu": self.mu,
"n_stumps_per_attribute": self.n_stumps_per_attribute,
"max_depth": self.max_depth}
def getInterpret(self, directory, y_test):
"""
Parameters
----------
directory :
y_test :
Returns
-------
string for interpretation 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)
......
......@@ -14,25 +14,28 @@ class RandomForest(RandomForestClassifier, BaseMonoviewClassifier):
Parameters
----------
random_state
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
n_estimators
n_estimators : int (default : 10) number of estimators
max_depth : int maximum of depth (default : 10)
max_depth : int , optional (default : None) maximum of depth
criterion : criteria (default : 'gini')
kwargs
kwargs : others arguments
Attributes
----------
param_names
param_names :
distribs
distribs :
classed_params
classed_params :
weird_strings
weird_strings :
"""
def __init__(self, random_state=None, n_estimators=10,
......
......@@ -18,7 +18,10 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
Parameters
----------
random_state
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
model_type
max_rules
p
......@@ -72,7 +75,7 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
Returns
-------
parame
parameters dictionary
"""
params = super(SCMPregen, self).get_params(deep)
params["estimators_generator"] = self.estimators_generator
......@@ -90,6 +93,7 @@ class SCMPregen(BaseMonoviewClassifier, PregenClassifier, scm):
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
......
......@@ -13,11 +13,28 @@ class SGD(SGDClassifier, BaseMonoviewClassifier):
Parameters
----------
random_state
loss
penalty
alpha
kwargs
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
loss : str , (default = "hinge")
penalty : str, (default = "l2")
alpha : float, (default = 0.0001)
kwargs : other arguments
Attributes
----------
param_names :
distribs :
classed_params :
weird_strings :
"""
def __init__(self, random_state=None, loss='hinge',
penalty='l2', alpha=0.0001, **kwargs):
......
......@@ -13,9 +13,15 @@ class SVMLinear(SVCClassifier, BaseMonoviewClassifier):
Parameters
----------
random_state
C
kwargs
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
C : float, optional (default=1.0)
Penalty parameter C of the error term.
kwargs : others arguments
"""
def __init__(self, random_state=None, C=1.0, **kwargs):
......
......@@ -14,13 +14,19 @@ class SVMPoly(SVCClassifier, BaseMonoviewClassifier):
Parameters
----------
random_state
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
C
degree
C : float, optional (default=1.0)
Penalty parameter C of the error term.
degree :
kwargs : others arguments
kwargs
Attributes
----------
......
......@@ -14,9 +14,13 @@ class SVMRBF(SVCClassifier, BaseMonoviewClassifier):
Parameters
----------
random_state
C
kwargs
random_state : int seed, RandomState instance, or None (default=None)
The seed of the pseudo random number generator to use when
shuffling the data.
C :
kwargs : others arguments
Attributes
----------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment