Skip to content

Commit

Permalink
revert 1
Browse files Browse the repository at this point in the history
  • Loading branch information
bcebere committed Nov 28, 2022
1 parent d01d251 commit 1f2287e
Showing 1 changed file with 3 additions and 43 deletions.
46 changes: 3 additions & 43 deletions src/autoprognosis/plugins/ensemble/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand Down Expand Up @@ -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 = [],
Expand All @@ -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")

Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand All @@ -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:
Expand Down

0 comments on commit 1f2287e

Please sign in to comment.