Skip to content

Commit

Permalink
Fix n_jobs in EleasticEnsembleClassifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
isaksamsten committed Feb 22, 2024
1 parent 1395bdf commit 103124b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/wildboar/ensemble/_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class ElasticEnsembleClassifier(ClassifierMixin, BaseEstimator):
n_jobs : int, optional
The number of paralell jobs.
Attributes
----------
scores : tuple
A tuple of metric name and cross-validation score.
References
----------
Jason Lines and Anthony Bagnall,
Expand Down Expand Up @@ -170,9 +175,9 @@ def fit(self, x, y):
cv=LeaveOneOut(),
n_jobs=self.n_jobs,
).fit(x, y)
estimator = gridcv.best_estimator_.set_params(n_jobs=-1).fit(x, y)
estimator = gridcv.best_estimator_.set_params(n_jobs=self.n_jobs).fit(x, y)
self.estimators_.append(estimator)
self.scores_.append(gridcv.best_score_)
self.scores_.append((metric, gridcv.best_score_))

return self

Expand All @@ -194,7 +199,9 @@ def predict_proba(self, x):
x = self._validate_data(x, allow_3d=True, reset=False)
proba = np.zeros((x.shape[0], len(self.estimators_), len(self.classes_)))
score_sum = 0
for i, (score, estimator) in enumerate(zip(self.scores_, self.estimators_)):
for i, ((_, score), estimator) in enumerate(
zip(self.scores_, self.estimators_)
):
proba[:, i] = estimator.predict_proba(x) * score
score_sum += score
return proba.sum(axis=1) / score_sum
Expand Down

0 comments on commit 103124b

Please sign in to comment.