Skip to content
Snippets Groups Projects
Commit f866e30d authored by Charly Lamothe's avatar Charly Lamothe
Browse files

Clean up some imports

parent a86dff87
Branches
Tags
1 merge request!3clean scripts
......@@ -27,6 +27,6 @@ class ModelFactory(object):
model_parameters = ModelParameters.load(directory_path, experiment_id)
model = ModelFactory.build(task, model_parameters)
# todo faire ce qu'il faut ici pour rétablir correctement le modèle
# model.set_forest(model_raw_results.forest)
# model.set_weights(model_raw_results.weights)
model.set_forest(model_raw_results.model_object.forest)
model.set_weights(model_raw_results.model_object.weights)
return model
from abc import abstractmethod, ABCMeta
from bolsonaro import LOG_PATH
from bolsonaro.error_handling.logger_factory import LoggerFactory
from abc import abstractmethod, ABCMeta
import numpy as np
from sklearn.linear_model import OrthogonalMatchingPursuit
from bolsonaro import LOG_PATH
from bolsonaro.error_handling.logger_factory import LoggerFactory
from sklearn.base import BaseEstimator
......@@ -21,7 +20,6 @@ class OmpForest(BaseEstimator, metaclass=ABCMeta):
def score_base_estimator(self, X, y):
return self._base_forest_estimator.score(X, y)
def _base_estimator_predictions(self, X):
return np.array([tree.predict(X) for tree in self._base_forest_estimator.estimators_]).T
......
from collections import namedtuple
from copy import deepcopy
from bolsonaro.models.omp_forest import OmpForest, SingleOmpForest
from bolsonaro.utils import binarize_class_data
from sklearn.base import BaseEstimator
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import OrthogonalMatchingPursuit
from bolsonaro import LOG_PATH
from bolsonaro.error_handling.logger_factory import LoggerFactory
from bolsonaro.models.omp_forest import OmpForest, SingleOmpForest
import numpy as np
from bolsonaro.utils import binarize_class_data
class OmpForestBinaryClassifier(SingleOmpForest):
DEFAULT_SCORE_METRIC = 'indicator'
def __init__(self, models_parameters):
estimator = RandomForestClassifier(n_estimators=models_parameters.forest_size,
estimator = RandomForestClassifier(**models_parameters.hyperparameters,
random_state=models_parameters.seed, n_jobs=-1)
super().__init__(models_parameters, estimator)
def _check_classes(self, y):
assert len(set(y).difference({-1, 1})) == 0, "Classes for binary classifier should be {-1, +1}"
assert len(set(y).difference({-1, 1})) == 0, "Classes for binary classifier must be {-1, +1}"
def fit(self, X_forest, y_forest, X_omp, y_omp):
self._check_classes(y_forest)
......@@ -31,7 +24,6 @@ class OmpForestBinaryClassifier(SingleOmpForest):
return super().fit(X_forest, y_forest, X_omp, y_omp)
def score(self, X, y, metric=DEFAULT_SCORE_METRIC):
"""
Evaluate OMPForestClassifer on (`X`, `y`) using `metric`
......@@ -56,7 +48,7 @@ class OmpForestMulticlassClassifier(OmpForest):
DEFAULT_SCORE_METRIC = 'indicator'
def __init__(self, models_parameters):
estimator = RandomForestClassifier(n_estimators=models_parameters.forest_size,
estimator = RandomForestClassifier(**models_parameters.hyperparameters,
random_state=models_parameters.seed, n_jobs=-1)
super().__init__(models_parameters, estimator)
# question: peut-être initialiser les omps dans le __init__? comme pour le SingleOmpForest
......@@ -95,7 +87,6 @@ class OmpForestMulticlassClassifier(OmpForest):
max_preds = np.argmax(preds, axis=1)
return np.array(label_names)[max_preds]
def score(self, X, y, metric=DEFAULT_SCORE_METRIC):
predictions = self.predict(X)
......@@ -107,8 +98,6 @@ class OmpForestMulticlassClassifier(OmpForest):
return evaluation
if __name__ == "__main__":
forest = RandomForestClassifier(n_estimators=10)
X = np.random.rand(10, 5)
......
from bolsonaro.models.omp_forest import SingleOmpForest
from sklearn.ensemble import RandomForestRegressor
import numpy as np
from bolsonaro.models.omp_forest import SingleOmpForest
class OmpForestRegressor(SingleOmpForest):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment