0

This is the code I was using for imbalanced data to do under sampling over dataset.

from collections import Counter
from imblearn.under_sampling import NearMiss
ns=NearMiss(0.8)
X_train_ns, y_train_ns = ns.fit_resample(X_train,y_train)
print("The number of classes before fit {}".format(Counter(y_train)))
print("The number of classes after fit {}".format(Counter(y_train_ns)))

When I'm passing a single argument in parameters its gives an error

TypeError                                 Traceback (most recent call last)
\~\\AppData\\Local\\Temp\\ipykernel_12520\\833215470.py in \<cell line: 3\>()
1 from collections import Counter
2 from imblearn.under_sampling import NearMiss
\----\> 3 ns=NearMiss(0.8)
4 X_train_ns, y_train_ns = ns.fit_resample(X_train,y_train)
5 print("The number of classes before fit {}".format(Counter(y_train)))

TypeError: __init__() takes 1 positional argument but 2 were given

When I do not pass any argument, it gives this ouput

from collections import Counter
from imblearn.under_sampling import NearMiss
ns=NearMiss()
X_train_ns, y_train_ns = ns.fit_resample(X_train,y_train)
print("The number of classes before fit {}".format(Counter(y_train)))
print("The number of classes after fit {}".format(Counter(y_train_ns)))


The number of classes before fit Counter({0: 199016, 1: 348})
The number of classes after fit Counter({0: 348, 1: 348})

I'm looking for the answer to the problem that I'm geeting error.

  • [`NearMiss`](https://imbalanced-learn.org/stable/references/generated/imblearn.under_sampling.NearMiss.html#imblearn.under_sampling.NearMiss) doesn't appear to take positional arguments, only keyword-only arguments. (`__init__`, of course, takes the newly constructed instance of `NearMiss` as one positional argument.)Try `NearMiss(sampling_strategy=0.8)`, as that's the only parameter that seems to accept a `float` as its value. – chepner Jan 21 '23 at 17:13

1 Answers1

0

NearMiss does not take positional arguments, only keyword arguments.

ns = NearMiss(sampling_strategy=0.8)
chepner
  • 497,756
  • 71
  • 530
  • 681