From 1f2287e7f975980fd44e4bbf8ffd5d1aae07152d Mon Sep 17 00:00:00 2001 From: Bogdan Cebere Date: Mon, 28 Nov 2022 17:33:59 +0000 Subject: [PATCH] revert 1 --- .../plugins/ensemble/classifiers.py | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/src/autoprognosis/plugins/ensemble/classifiers.py b/src/autoprognosis/plugins/ensemble/classifiers.py index 45261fd9..dd7f4730 100644 --- a/src/autoprognosis/plugins/ensemble/classifiers.py +++ b/src/autoprognosis/plugins/ensemble/classifiers.py @@ -91,22 +91,12 @@ def __init__( self.explanations_nepoch = explanations_nepoch self.explainers = explainers - self._fitted = True - for model in models: - self._fitted |= model.is_fitted() - for idx, weight in enumerate(weights): if weight == 0: continue self.models.append(models[idx]) self.weights.append(weights[idx]) - def is_fitted(self) -> bool: - try: - return self._fitted - except BaseException: - return True # backwards compatible - def fit(self, X: pd.DataFrame, Y: pd.DataFrame) -> "WeightedEnsemble": def fit_model(k: int) -> Any: return self.models[k].fit(X, Y) @@ -131,13 +121,9 @@ def fit_model(k: int) -> Any: ) self.explainers[exp] = exp_model - self._fitted = True return self def predict_proba(self, X: pd.DataFrame, *args: Any) -> pd.DataFrame: - if not self.is_fitted(): - raise RuntimeError("Fit the model first") - preds_ = [] for k in range(len(self.models)): preds_.append(self.models[k].predict_proba(X, *args) * self.weights[k]) @@ -322,7 +308,7 @@ def __init__( self, models: List[PipelineMeta], meta_model: PipelineMeta = Pipeline( - ["imputer.default.ice", "prediction.classifier.logistic_regression"] + ["prediction.classifier.logistic_regression"] )(output="numpy"), clf: Union[None, Stacking] = None, explainer_plugins: list = [], @@ -337,10 +323,6 @@ def __init__( self.explainers: Optional[dict] self.explanations_nepoch = explanations_nepoch - self._fitted = True - for model in models: - self._fitted |= model.is_fitted() - for model in self.models: model.change_output("numpy") @@ -353,12 +335,6 @@ def __init__( use_proba=True, ) - def is_fitted(self) -> bool: - try: - return self._fitted - except BaseException: - return True # backwards compatible - def fit(self, X: pd.DataFrame, Y: pd.DataFrame) -> "StackingEnsemble": self.clf.fit(X, Y) @@ -373,13 +349,10 @@ def fit(self, X: pd.DataFrame, Y: pd.DataFrame) -> "StackingEnsemble": n_epoch=self.explanations_nepoch, prefit=True, ) - self._fitted = True + return self def predict_proba(self, X: pd.DataFrame, *args: Any) -> pd.DataFrame: - if not self.is_fitted(): - raise RuntimeError("Fit the model first") - return pd.DataFrame(self.clf.predict_proba(X)) def explain(self, X: pd.DataFrame, *args: Any) -> pd.DataFrame: @@ -455,21 +428,11 @@ def __init__( self.explainers: Optional[dict] self.explanations_nepoch = explanations_nepoch - self._fitted = True - for model in models: - self._fitted |= model.is_fitted() - if clf: self.clf = clf else: self.clf = SimpleClassifierAggregator(models, method=method) - def is_fitted(self) -> bool: - try: - return self._fitted - except BaseException: - return True # backwards compatible - def fit(self, X: pd.DataFrame, Y: pd.DataFrame) -> "AggregatingEnsemble": Y = pd.DataFrame(Y).values.ravel() @@ -486,13 +449,10 @@ def fit(self, X: pd.DataFrame, Y: pd.DataFrame) -> "AggregatingEnsemble": n_epoch=self.explanations_nepoch, prefit=True, ) - self._fitted = True + return self def predict_proba(self, X: pd.DataFrame, *args: Any) -> pd.DataFrame: - if not self.is_fitted(): - raise RuntimeError("Fit the model first") - return pd.DataFrame(self.clf.predict_proba(X)) def explain(self, X: pd.DataFrame, *args: Any) -> pd.DataFrame: