NearMiss在传递参数时给出此错误:__init__()接受1个位置参数,但给出了2个



这是我对不平衡数据在数据集上进行抽样的代码。

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)))

当我在参数中传递一个参数时它会给出一个错误

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

当我不传递任何参数时,它给出如下输出

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})

我正在寻找我遇到错误的问题的答案。

NearMiss不接受位置参数,只接受关键字参数。

ns = NearMiss(sampling_strategy=0.8)

最新更新