Rohit Bale
Rohit Bale

Reputation: 15

NearMiss gives this error when an argument is passed: __init__() takes 1 positional argument but 2 were given

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.

Upvotes: 0

Views: 336

Answers (1)

chepner
chepner

Reputation: 532093

NearMiss does not take positional arguments, only keyword arguments.

ns = NearMiss(sampling_strategy=0.8)

Upvotes: 0

Related Questions