Search code examples
pythonmachine-learningimblearn

How to get sample indices from RandomUnderSampler in imblearn


Does anyone know if/how one can get the indices of the selected samples after undersampling with imblearn's RandomUnderSampler? There used to be the argument "return_indices=True" which was now removed for the new version and supposingly was replaced with an attribute "sample_indices_". However, if I try to use that attribute, it doesn't work (see code below). I'm using imblearn version 0.6.2.

russs = RandomUnderSampler(random_state=0,sampling_strategy={6: 600}).fit(X_train_point,y_train_point)
russs.sample_indices_

AttributeError                            Traceback (most recent call last)
<ipython-input-78-8397ba40f19b> in <module>
      1 russs = RandomUnderSampler(random_state=0,sampling_strategy={6: 600}).fit(X_train_point,y_train_point)
----> 2 russs.sample_indices

AttributeError: 'RandomUnderSampler' object has no attribute 'sample_indices'

Solution

  • Also facing this.. Despite the fact that the docs say Deprecated since version 0.4: return_indices is deprecated. Use the attribute sample_indices_ instead. I reverted to 0.5.0 and am able to use the old return_indices=True argument.

    pip install imbalanced-learn==0.5.0