diff --git a/code/bolsonaro/models/model_parameters.py b/code/bolsonaro/models/model_parameters.py index a3286edfccce7fddf4a4174b6cffddd5cf78717d..2009190e47726e012d8b6dd8d2559fc28f125a22 100644 --- a/code/bolsonaro/models/model_parameters.py +++ b/code/bolsonaro/models/model_parameters.py @@ -7,6 +7,20 @@ class ModelParameters(object): def __init__(self, extracted_forest_size, normalize_D, subsets_used, normalize_weights, seed, hyperparameters, extraction_strategy): + """Init of ModelParameters. + + Args: + extracted_forest_size (list): list of all the extracted forest + size. + normalize_D (bool): true normalize the distribution, false no + subsets_used (list): which dataset use for randomForest and for OMP + 'train', 'dev' or 'train+dev' and combination of two of this. + normalize_weights (bool): if we normalize the weights or no. + seed (int): the seed used for the randomization. + hyperparameters (dict): dict of the hyperparameters of RandomForest + in scikit-learn. + extraction_strategy (str): either 'none', 'random', 'omp' + """ self._extracted_forest_size = extracted_forest_size self._normalize_D = normalize_D self._subsets_used = subsets_used diff --git a/requirements.txt b/requirements.txt index 14dcb5ed8a83d5e2a827709c373b39db7775d7a0..38a47c2beeff7ee073c27b9dd7ed9cabfbc12c4f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ Sphinx coverage awscli flake8 - +pytest scikit-learn git+git://github.com/darenr/scikit-optimize@master python-dotenv diff --git a/tests/test_bolsonaro.py b/tests/test_bolsonaro.py new file mode 100644 index 0000000000000000000000000000000000000000..e282f20c9385ad1d35dcdc2506404d0377048963 --- /dev/null +++ b/tests/test_bolsonaro.py @@ -0,0 +1,58 @@ +import numpy as np + +from bolsonaro.models.model_parameters import ModelParameters +from bolsonaro.models.omp_forest_classifier import OmpForestBinaryClassifier, OmpForestMulticlassClassifier +from bolsonaro.models.omp_forest_regressor import OmpForestRegressor + + +def test_binary_classif_omp(): + + model_parameters = ModelParameters( + 1, False, ['train+dev', 'train+dev'], False, 1, + {'n_estimators': 100}, 'omp' + ) + + omp_forest = OmpForestBinaryClassifier(model_parameters) + X_train = [[1, 0], [0, 1]] + y_train = [-1, 1] + + omp_forest.fit(X_train, y_train, X_train, y_train) + + results = omp_forest.predict(X_train) + + assert isinstance(results, np.ndarray) + + +def test_regression_omp(): + + model_parameters = ModelParameters( + 1, False, ['train+dev', 'train+dev'], False, 1, + {'n_estimators': 100}, 'omp' + ) + + omp_forest = OmpForestRegressor(model_parameters) + X_train = [[1, 0], [0, 1]] + y_train = [-1, 1] + + omp_forest.fit(X_train, y_train, X_train, y_train) + + results = omp_forest.predict(X_train) + + assert isinstance(results, np.ndarray) + +def test_multiclassif_omp(): + + model_parameters = ModelParameters( + 1, False, ['train+dev', 'train+dev'], False, 1, + {'n_estimators': 100}, 'omp' + ) + + omp_forest = OmpForestMulticlassClassifier(model_parameters) + X_train = [[1, 0], [0, 1]] + y_train = [-1, 1] + + omp_forest.fit(X_train, y_train, X_train, y_train) + + results = omp_forest.predict(X_train) + + assert isinstance(results, np.ndarray)