Skip to content

FIX reproducibility and parallelization of InstanceHardnessThreshold #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from sklearn.base import ClassifierMixin, clone
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import StratifiedKFold,cross_val_predict
from sklearn.utils import safe_indexing

from ..base import BaseUnderSampler
Expand Down Expand Up @@ -126,6 +126,7 @@ def _validate_estimator(self):
isinstance(self.estimator, ClassifierMixin) and
hasattr(self.estimator, 'predict_proba')):
self.estimator_ = clone(self.estimator)
self.estimator_.set_params(n_jobs=1,random_state=self.random_state)
elif self.estimator is None:
self.estimator_ = RandomForestClassifier(
n_estimators=100, random_state=self.random_state,
Expand All @@ -143,19 +144,10 @@ def _fit_resample(self, X, y):
target_stats = Counter(y)
skf = StratifiedKFold(
n_splits=self.cv, shuffle=False,
random_state=self.random_state).split(X, y)
probabilities = np.zeros(y.shape[0], dtype=float)

for train_index, test_index in skf:
X_train = safe_indexing(X, train_index)
X_test = safe_indexing(X, test_index)
y_train = safe_indexing(y, train_index)
y_test = safe_indexing(y, test_index)

self.estimator_.fit(X_train, y_train)

probs = self.estimator_.predict_proba(X_test)
probabilities[test_index] = probs[range(len(y_test)), y_test]
random_state=self.random_state)
probabilities = cross_val_predict(self.estimator_, X, y, cv=skf,
n_jobs=self.n_jobs, method='predict_proba')
probabilities = probabilities[range(len(y)), y]

idx_under = np.empty((0, ), dtype=int)

Expand Down