@@ -35,7 +35,7 @@ class BalancedBatchGenerator(ParentClass):
3535 Create a keras ``Sequence`` which is given to ``fit_generator``. The
3636 sampler defines the sampling strategy used to balance the dataset ahead of
3737 creating the batch. The sampler should have an attribute
38- ``return_indices ``.
38+ ``sample_indices_ ``.
3939
4040 Parameters
4141 ----------
@@ -49,7 +49,7 @@ class BalancedBatchGenerator(ParentClass):
4949 Sample weight.
5050
5151 sampler : object or None, optional (default=RandomUnderSampler)
52- A sampler instance which has an attribute ``return_indices ``.
52+ A sampler instance which has an attribute ``sample_indices_ ``.
5353 By default, the sampler used is a
5454 :class:`imblearn.under_sampling.RandomUnderSampler`.
5555
@@ -118,20 +118,18 @@ def __init__(self, X, y, sample_weight=None, sampler=None, batch_size=32,
118118 def _sample (self ):
119119 random_state = check_random_state (self .random_state )
120120 if self .sampler is None :
121- self .sampler_ = RandomUnderSampler (return_indices = True ,
122- random_state = random_state )
121+ self .sampler_ = RandomUnderSampler (random_state = random_state )
123122 else :
124- if not hasattr (self .sampler , 'return_indices' ):
125- raise ValueError ("'sampler' needs to return the indices of "
126- "the samples selected. Provide a sampler "
127- "which has an attribute 'return_indices'." )
128123 self .sampler_ = clone (self .sampler )
129- self .sampler_ .set_params (return_indices = True )
130124 # FIXME: Remove in 0.6
131125 if self .sampler_ .__class__ .__name__ not in DONT_HAVE_RANDOM_STATE :
132126 set_random_state (self .sampler_ , random_state )
133127
134- _ , _ , self .indices_ = self .sampler_ .fit_resample (self .X , self .y )
128+ self .sampler_ .fit_resample (self .X , self .y )
129+ if not hasattr (self .sampler_ , 'sample_indices_' ):
130+ raise ValueError ("'sampler' needs to have an attribute "
131+ "'sample_indices_'." )
132+ self .indices_ = self .sampler_ .sample_indices_
135133 # shuffle the indices since the sampler are packing them by class
136134 random_state .shuffle (self .indices_ )
137135
@@ -168,7 +166,7 @@ def balanced_batch_generator(X, y, sample_weight=None, sampler=None,
168166 Returns a generator --- as well as the number of step per epoch --- which
169167 is given to ``fit_generator``. The sampler defines the sampling strategy
170168 used to balance the dataset ahead of creating the batch. The sampler should
171- have an attribute ``return_indices ``.
169+ have an attribute ``sample_indices_ ``.
172170
173171 Parameters
174172 ----------
@@ -182,7 +180,7 @@ def balanced_batch_generator(X, y, sample_weight=None, sampler=None,
182180 Sample weight.
183181
184182 sampler : object or None, optional (default=RandomUnderSampler)
185- A sampler instance which has an attribute ``return_indices ``.
183+ A sampler instance which has an attribute ``sample_indices_ ``.
186184 By default, the sampler used is a
187185 :class:`imblearn.under_sampling.RandomUnderSampler`.
188186
0 commit comments