2

Detailed Image

This is the code below which shows the error.

from imblearn.under_sampling import NearMiss
nm = NearMiss()
X_res,y_res=nm.fit_sample(X,Y)
Yashraj Jain
  • 88
  • 2
  • 8
  • that code fails with `X is not defined`. is there a small **self contained** runnable example you could share? – Tadhg McDonald-Jensen Jul 08 '20 at 17:49
  • 1
    the issue though does seem odd, code inside the library is calling an internal method that just doesn't exist? seems like a library issue most likely, could you provide the version of imblearn? (look for `imblearn.version` if it exists or maybe `imblearn.__version__`) – Tadhg McDonald-Jensen Jul 08 '20 at 17:52

2 Answers2

1

You are probably trying to under sample your imbalanced dataset. For this purpose, you can use RandomUnderSampler instead of NearMiss.

Try the following code:

from imblearn.under_sampling import RandomUnderSampler  

under_sampler = RandomUnderSampler()
X_res, y_res = under_sampler.fit_resample(X, y)

Now, your dataset is balanced. You can verify it using y_res.value_counts().

Cheers!

Harsh Dhamecha
  • 116
  • 3
  • 12
  • Is there a specific reason why it's better to use `RandomUnderSampler` instead `NearMiss` ? – Kiwi Feb 15 '22 at 10:13
0

Instead of "imblearn" package my conda installed a package named "imbalanced-learn" that's why it does not take the data. But it is strange that the jupyter notebook doesn't tell me that "imblearn" isn't installed.

Yashraj Jain
  • 88
  • 2
  • 8