Skip to content

Commit 531c91e

Browse files
authored
Modified the level of the random_state in the class hierarchy (#178)
1 parent 0573d83 commit 531c91e

17 files changed

+38
-48
lines changed

imblearn/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SamplerMixin(six.with_metaclass(ABCMeta, BaseEstimator)):
2525

2626
_estimator_type = 'sampler'
2727

28-
def __init__(self, ratio='auto'):
28+
def __init__(self, ratio='auto', random_state=None):
2929
"""Initialize this object and its instance variables.
3030
3131
Parameters
@@ -36,13 +36,20 @@ def __init__(self, ratio='auto'):
3636
of samples in the minority class over the the number of samples
3737
in the majority class.
3838
39+
random_state : int, RandomState instance or None, optional (default=None)
40+
If int, random_state is the seed used by the random number generator;
41+
If RandomState instance, random_state is the random number generator;
42+
If None, the random number generator is the RandomState instance used
43+
by np.random.
44+
3945
Returns
4046
-------
4147
None
4248
4349
"""
4450

4551
self.ratio = ratio
52+
self.random_state = random_state
4653
self.logger = logging.getLogger(__name__)
4754

4855
def fit(self, X, y):

imblearn/combine/smote_enn.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def __init__(self, ratio='auto', random_state=None,
115115
size_ngh=None, n_neighbors=3, kind_enn='all', n_jobs=-1,
116116
**kwargs):
117117

118-
super(SMOTEENN, self).__init__(ratio=ratio)
119-
self.random_state = random_state
118+
super(SMOTEENN, self).__init__(ratio=ratio, random_state=random_state)
120119
self.k = k
121120
self.m = m
122121
self.out_step = out_step

imblearn/combine/smote_tomek.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class SMOTETomek(BaseBinarySampler):
101101
def __init__(self, ratio='auto', random_state=None,
102102
k=5, m=10, out_step=0.5, kind_smote='regular',
103103
n_jobs=-1, **kwargs):
104-
super(SMOTETomek, self).__init__(ratio=ratio)
105-
self.random_state = random_state
104+
super(SMOTETomek, self).__init__(ratio=ratio,
105+
random_state=random_state)
106106
self.k = k
107107
self.m = m
108108
self.out_step = out_step

imblearn/ensemble/balance_cascade.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ class BalanceCascade(BaseBinarySampler):
102102
def __init__(self, ratio='auto', return_indices=False, random_state=None,
103103
n_max_subset=None, classifier='knn', bootstrap=True,
104104
**kwargs):
105-
super(BalanceCascade, self).__init__(ratio=ratio)
105+
super(BalanceCascade, self).__init__(ratio=ratio,
106+
random_state=random_state)
106107
self.return_indices = return_indices
107-
self.random_state = random_state
108108
self.classifier = classifier
109109
self.n_max_subset = n_max_subset
110110
self.bootstrap = bootstrap

imblearn/ensemble/easy_ensemble.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class EasyEnsemble(BaseMulticlassSampler):
9090

9191
def __init__(self, ratio='auto', return_indices=False,
9292
random_state=None, replacement=False, n_subsets=10):
93-
super(EasyEnsemble, self).__init__(ratio=ratio)
93+
super(EasyEnsemble, self).__init__(ratio=ratio,
94+
random_state=random_state)
9495
self.return_indices = return_indices
95-
self.random_state = random_state
9696
self.replacement = replacement
9797
self.n_subsets = n_subsets
9898

imblearn/over_sampling/adasyn.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,8 @@ class ADASYN(BaseBinarySampler):
8484
8585
"""
8686

87-
def __init__(self,
88-
ratio='auto',
89-
random_state=None,
90-
k=5,
91-
n_jobs=1):
92-
super(ADASYN, self).__init__(ratio=ratio)
93-
self.random_state = random_state
87+
def __init__(self, ratio='auto', random_state=None, k=5, n_jobs=1):
88+
super(ADASYN, self).__init__(ratio=ratio, random_state=random_state)
9489
self.k = k
9590
self.n_jobs = n_jobs
9691
self.nearest_neighbour = NearestNeighbors(n_neighbors=self.k + 1,

imblearn/over_sampling/random_over_sampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def __init__(self,
7272
ratio='auto',
7373
random_state=None):
7474

75-
super(RandomOverSampler, self).__init__(ratio=ratio)
76-
self.random_state = random_state
75+
super(RandomOverSampler, self).__init__(ratio=ratio,
76+
random_state=random_state)
7777

7878
def _sample(self, X, y):
7979
"""Resample the dataset.

imblearn/over_sampling/smote.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,9 @@ class SMOTE(BaseBinarySampler):
102102
103103
"""
104104

105-
def __init__(self,
106-
ratio='auto',
107-
random_state=None,
108-
k=5,
109-
m=10,
110-
out_step=0.5,
111-
kind='regular',
112-
n_jobs=-1,
113-
**kwargs):
114-
super(SMOTE, self).__init__(ratio=ratio)
115-
self.random_state = random_state
105+
def __init__(self, ratio='auto', random_state=None, k=5, m=10,
106+
out_step=0.5, kind='regular', n_jobs=-1, **kwargs):
107+
super(SMOTE, self).__init__(ratio=ratio, random_state=random_state)
116108
self.kind = kind
117109
self.k = k
118110
self.m = m

imblearn/under_sampling/cluster_centroids.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class ClusterCentroids(BaseMulticlassSampler):
8080
"""
8181

8282
def __init__(self, ratio='auto', random_state=None, n_jobs=-1, **kwargs):
83-
super(ClusterCentroids, self).__init__(ratio=ratio)
84-
self.random_state = random_state
83+
super(ClusterCentroids, self).__init__(ratio=ratio,
84+
random_state=random_state)
8585
self.n_jobs = n_jobs
8686
self.kwargs = kwargs
8787

imblearn/under_sampling/condensed_nearest_neighbour.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ class CondensedNearestNeighbour(BaseMulticlassSampler):
9797
def __init__(self, return_indices=False, random_state=None,
9898
size_ngh=None, n_neighbors=1, n_seeds_S=1, n_jobs=-1,
9999
**kwargs):
100-
super(CondensedNearestNeighbour, self).__init__()
101-
100+
super(CondensedNearestNeighbour, self).__init__(
101+
random_state=random_state)
102102
self.return_indices = return_indices
103-
self.random_state = random_state
104103
self.size_ngh = size_ngh
105104
self.n_neighbors = n_neighbors
106105
self.n_seeds_S = n_seeds_S

0 commit comments

Comments
 (0)