imblearn/ensemble/_forest.py
Killed 88 out of 137 mutantsSurvived
Survived mutation testing. These mutants show holes in your test suite.Mutant 119
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -36,7 +36,7 @@
from ..utils._validation import check_sampling_strategy
from ..utils._validation import _deprecate_positional_args
-MAX_INT = np.iinfo(np.int32).max
+MAX_INT = None
def _local_parallel_build_trees(
Mutant 122
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -56,7 +56,7 @@
X_resampled, y_resampled = sampler.fit_resample(X, y)
if sample_weight is not None:
sample_weight = _safe_indexing(sample_weight, sampler.sample_indices_)
- if _get_n_samples_bootstrap is not None:
+ if _get_n_samples_bootstrap is None:
n_samples_bootstrap = min(n_samples_bootstrap, X_resampled.shape[0])
tree = _parallel_build_trees(
tree,
Mutant 125
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -298,7 +298,6 @@
[1]
"""
- @_deprecate_positional_args
def __init__(
self,
n_estimators=100,
Mutant 126
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -301,7 +301,7 @@
@_deprecate_positional_args
def __init__(
self,
- n_estimators=100,
+ n_estimators=101,
*,
criterion="gini",
max_depth=None,
Mutant 128
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -305,7 +305,7 @@
*,
criterion="gini",
max_depth=None,
- min_samples_split=2,
+ min_samples_split=3,
min_samples_leaf=1,
min_weight_fraction_leaf=0.0,
max_features="auto",
Mutant 129
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -306,7 +306,7 @@
criterion="gini",
max_depth=None,
min_samples_split=2,
- min_samples_leaf=1,
+ min_samples_leaf=2,
min_weight_fraction_leaf=0.0,
max_features="auto",
max_leaf_nodes=None,
Mutant 134
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -312,7 +312,7 @@
max_leaf_nodes=None,
min_impurity_decrease=0.0,
bootstrap=True,
- oob_score=False,
+ oob_score=True,
sampling_strategy="auto",
replacement=False,
n_jobs=None,
Mutant 136
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -314,7 +314,7 @@
bootstrap=True,
oob_score=False,
sampling_strategy="auto",
- replacement=False,
+ replacement=True,
n_jobs=None,
random_state=None,
verbose=0,
Mutant 137
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -317,7 +317,7 @@
replacement=False,
n_jobs=None,
random_state=None,
- verbose=0,
+ verbose=1,
warm_start=False,
class_weight=None,
ccp_alpha=0.0,
Mutant 138
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -318,7 +318,7 @@
n_jobs=None,
random_state=None,
verbose=0,
- warm_start=False,
+ warm_start=True,
class_weight=None,
ccp_alpha=0.0,
max_samples=None,
Mutant 141
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -345,7 +345,7 @@
)
self.sampling_strategy = sampling_strategy
- self.replacement = replacement
+ self.replacement = None
def _validate_estimator(self, default=DecisionTreeClassifier()):
"""Check the estimator and the n_estimator attribute, set the
Mutant 143
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -356,7 +356,7 @@
"got {}.".format(type(self.n_estimators))
)
- if self.n_estimators <= 0:
+ if self.n_estimators < 0:
raise ValueError(
"n_estimators must be greater than zero, "
"got {}.".format(self.n_estimators)
Mutant 145
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -362,7 +362,7 @@
"got {}.".format(self.n_estimators)
)
- if self.base_estimator is not None:
+ if self.base_estimator is None:
self.base_estimator_ = clone(self.base_estimator)
else:
self.base_estimator_ = clone(default)
Mutant 149
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -383,7 +383,7 @@
)
sampler = clone(self.base_sampler_)
- if random_state is not None:
+ if random_state is None:
_set_random_states(estimator, random_state)
_set_random_states(sampler, random_state)
Mutant 150
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -421,7 +421,7 @@
raise ValueError(
"sparse multilabel-indicator for y is not supported."
)
- X, y = self._validate_data(X, y, multi_output=True,
+ X, y = self._validate_data(X, y, multi_output=False,
accept_sparse="csc", dtype=DTYPE)
if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)
Mutant 151
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -422,7 +422,7 @@
"sparse multilabel-indicator for y is not supported."
)
X, y = self._validate_data(X, y, multi_output=True,
- accept_sparse="csc", dtype=DTYPE)
+ accept_sparse="XXcscXX", dtype=DTYPE)
if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)
Mutant 153
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -423,7 +423,7 @@
)
X, y = self._validate_data(X, y, multi_output=True,
accept_sparse="csc", dtype=DTYPE)
- if sample_weight is not None:
+ if sample_weight is None:
sample_weight = _check_sample_weight(sample_weight, X)
if issparse(X):
Mutant 157
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -435,7 +435,7 @@
_, self.n_features_ = X.shape
y = np.atleast_1d(y)
- if y.ndim == 2 and y.shape[1] == 1:
+ if y.ndim == 3 and y.shape[1] == 1:
warn(
"A column-vector y was passed when a 1d array was"
" expected. Please change the shape of y to "
Mutant 158
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -435,7 +435,7 @@
_, self.n_features_ = X.shape
y = np.atleast_1d(y)
- if y.ndim == 2 and y.shape[1] == 1:
+ if y.ndim == 2 and y.shape[2] == 1:
warn(
"A column-vector y was passed when a 1d array was"
" expected. Please change the shape of y to "
Mutant 159
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -435,7 +435,7 @@
_, self.n_features_ = X.shape
y = np.atleast_1d(y)
- if y.ndim == 2 and y.shape[1] == 1:
+ if y.ndim == 2 and y.shape[1] != 1:
warn(
"A column-vector y was passed when a 1d array was"
" expected. Please change the shape of y to "
Mutant 160
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -435,7 +435,7 @@
_, self.n_features_ = X.shape
y = np.atleast_1d(y)
- if y.ndim == 2 and y.shape[1] == 1:
+ if y.ndim == 2 and y.shape[1] == 2:
warn(
"A column-vector y was passed when a 1d array was"
" expected. Please change the shape of y to "
Mutant 165
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -447,7 +447,7 @@
if y.ndim == 1:
# reshape is necessary to preserve the data contiguity against vs
# [:, np.newaxis] that does not.
- y = np.reshape(y, (-1, 1))
+ y = np.reshape(y, (-2, 1))
self.n_outputs_ = y.shape[1]
Mutant 171
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -453,7 +453,7 @@
y_encoded, expanded_class_weight = self._validate_y_class_weight(y)
- if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
+ if getattr(y, "XXdtypeXX", None) != DOUBLE or not y.flags.contiguous:
y_encoded = np.ascontiguousarray(y_encoded, dtype=DOUBLE)
if isinstance(self.sampling_strategy, dict):
Mutant 172
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -453,7 +453,7 @@
y_encoded, expanded_class_weight = self._validate_y_class_weight(y)
- if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
+ if getattr(y, "dtype", None) == DOUBLE or not y.flags.contiguous:
y_encoded = np.ascontiguousarray(y_encoded, dtype=DOUBLE)
if isinstance(self.sampling_strategy, dict):
Mutant 173
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -453,7 +453,7 @@
y_encoded, expanded_class_weight = self._validate_y_class_weight(y)
- if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
+ if getattr(y, "dtype", None) != DOUBLE or y.flags.contiguous:
y_encoded = np.ascontiguousarray(y_encoded, dtype=DOUBLE)
if isinstance(self.sampling_strategy, dict):
Mutant 174
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -453,7 +453,7 @@
y_encoded, expanded_class_weight = self._validate_y_class_weight(y)
- if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
+ if getattr(y, "dtype", None) != DOUBLE and not y.flags.contiguous:
y_encoded = np.ascontiguousarray(y_encoded, dtype=DOUBLE)
if isinstance(self.sampling_strategy, dict):
Mutant 177
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -466,7 +466,7 @@
else:
self._sampling_strategy = self.sampling_strategy
- if expanded_class_weight is not None:
+ if expanded_class_weight is None:
if sample_weight is not None:
sample_weight = sample_weight * expanded_class_weight
else:
Mutant 181
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -486,7 +486,7 @@
"Out of bag estimation only available" " if bootstrap=True"
)
- random_state = check_random_state(self.random_state)
+ random_state = None
if not self.warm_start or not hasattr(self, "estimators_"):
# Free allocated memory, if any
Mutant 182
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -488,7 +488,7 @@
random_state = check_random_state(self.random_state)
- if not self.warm_start or not hasattr(self, "estimators_"):
+ if self.warm_start or not hasattr(self, "estimators_"):
# Free allocated memory, if any
self.estimators_ = []
self.samplers_ = []
Mutant 183
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -488,7 +488,7 @@
random_state = check_random_state(self.random_state)
- if not self.warm_start or not hasattr(self, "estimators_"):
+ if not self.warm_start or hasattr(self, "estimators_"):
# Free allocated memory, if any
self.estimators_ = []
self.samplers_ = []
Mutant 184
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -488,7 +488,7 @@
random_state = check_random_state(self.random_state)
- if not self.warm_start or not hasattr(self, "estimators_"):
+ if not self.warm_start or not hasattr(self, "XXestimators_XX"):
# Free allocated memory, if any
self.estimators_ = []
self.samplers_ = []
Mutant 185
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -488,7 +488,7 @@
random_state = check_random_state(self.random_state)
- if not self.warm_start or not hasattr(self, "estimators_"):
+ if not self.warm_start and not hasattr(self, "estimators_"):
# Free allocated memory, if any
self.estimators_ = []
self.samplers_ = []
Mutant 189
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -494,7 +494,7 @@
self.samplers_ = []
self.pipelines_ = []
- n_more_estimators = self.n_estimators - len(self.estimators_)
+ n_more_estimators = self.n_estimators + len(self.estimators_)
if n_more_estimators < 0:
raise ValueError(
Mutant 191
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -496,7 +496,7 @@
n_more_estimators = self.n_estimators - len(self.estimators_)
- if n_more_estimators < 0:
+ if n_more_estimators <= 0:
raise ValueError(
"n_estimators=%d must be larger or equal to "
"len(estimators_)=%d when warm_start==True"
Mutant 192
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -496,7 +496,7 @@
n_more_estimators = self.n_estimators - len(self.estimators_)
- if n_more_estimators < 0:
+ if n_more_estimators < 1:
raise ValueError(
"n_estimators=%d must be larger or equal to "
"len(estimators_)=%d when warm_start==True"
Mutant 195
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -509,7 +509,7 @@
"fit new trees."
)
else:
- if self.warm_start and len(self.estimators_) > 0:
+ if self.warm_start and len(self.estimators_) >= 0:
# We draw from the random state to get the random state we
# would have got if we hadn't used a warm_start.
random_state.randint(MAX_INT, size=len(self.estimators_))
Mutant 196
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -509,7 +509,7 @@
"fit new trees."
)
else:
- if self.warm_start and len(self.estimators_) > 0:
+ if self.warm_start and len(self.estimators_) > 1:
# We draw from the random state to get the random state we
# would have got if we hadn't used a warm_start.
random_state.randint(MAX_INT, size=len(self.estimators_))
Mutant 197
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -509,7 +509,7 @@
"fit new trees."
)
else:
- if self.warm_start and len(self.estimators_) > 0:
+ if self.warm_start or len(self.estimators_) > 0:
# We draw from the random state to get the random state we
# would have got if we hadn't used a warm_start.
random_state.randint(MAX_INT, size=len(self.estimators_))
Mutant 207
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -565,7 +565,7 @@
self._set_oob_score(X, y_encoded)
# Decapsulate classes_ attributes
- if hasattr(self, "classes_") and self.n_outputs_ == 1:
+ if hasattr(self, "classes_") or self.n_outputs_ == 1:
self.n_classes_ = self.n_classes_[0]
self.classes_ = self.classes_[0]
Mutant 212
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -573,7 +573,7 @@
def _set_oob_score(self, X, y):
"""Compute out-of-bag score."""
- X = check_array(X, dtype=DTYPE, accept_sparse='csr')
+ X = check_array(X, dtype=DTYPE, accept_sparse='XXcsrXX')
n_classes_ = self.n_classes_
n_samples = y.shape[0]
Mutant 225
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -596,7 +596,7 @@
estimator.random_state, n_sample_subset, n_samples_bootstrap
)
p_estimator = estimator.predict_proba(
- X_resample[unsampled_indices, :], check_input=False
+ X_resample[unsampled_indices, :], check_input=True
)
if self.n_outputs_ == 1:
Mutant 233
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -607,7 +607,7 @@
predictions[k][indices, :] += p_estimator[k]
for k in range(self.n_outputs_):
- if (predictions[k].sum(axis=1) == 0).any():
+ if (predictions[k].sum(axis=1) != 0).any():
warn("Some inputs do not have OOB scores. "
"This probably means too few trees were used "
"to compute any reliable oob estimates.")
Mutant 234
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -607,7 +607,7 @@
predictions[k][indices, :] += p_estimator[k]
for k in range(self.n_outputs_):
- if (predictions[k].sum(axis=1) == 0).any():
+ if (predictions[k].sum(axis=1) == 1).any():
warn("Some inputs do not have OOB scores. "
"This probably means too few trees were used "
"to compute any reliable oob estimates.")
Mutant 235
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -608,7 +608,7 @@
for k in range(self.n_outputs_):
if (predictions[k].sum(axis=1) == 0).any():
- warn("Some inputs do not have OOB scores. "
+ warn("XXSome inputs do not have OOB scores. XX"
"This probably means too few trees were used "
"to compute any reliable oob estimates.")
Mutant 243
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -619,7 +619,7 @@
predictions[k].sum(axis=1)[:, np.newaxis])
mask_scores = np.isnan(np.sum(decision, axis=1))
oob_decision_function.append(decision)
- oob_score += np.mean(
+ oob_score = np.mean(
y[~mask_scores, k] == np.argmax(predictions[k][~mask_scores],
axis=1),
axis=0)
Mutant 250
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -624,7 +624,7 @@
axis=1),
axis=0)
- if self.n_outputs_ == 1:
+ if self.n_outputs_ != 1:
self.oob_decision_function_ = oob_decision_function[0]
else:
self.oob_decision_function_ = oob_decision_function
Mutant 251
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -624,7 +624,7 @@
axis=1),
axis=0)
- if self.n_outputs_ == 1:
+ if self.n_outputs_ == 2:
self.oob_decision_function_ = oob_decision_function[0]
else:
self.oob_decision_function_ = oob_decision_function
Mutant 253
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -625,7 +625,7 @@
axis=0)
if self.n_outputs_ == 1:
- self.oob_decision_function_ = oob_decision_function[0]
+ self.oob_decision_function_ = None
else:
self.oob_decision_function_ = oob_decision_function
Mutant 254
--- imblearn/ensemble/_forest.py
+++ imblearn/ensemble/_forest.py
@@ -629,7 +629,7 @@
else:
self.oob_decision_function_ = oob_decision_function
- self.oob_score_ = oob_score / self.n_outputs_
+ self.oob_score_ = oob_score * self.n_outputs_
def _more_tags(self):
return {"multioutput": False}