[英]NearMiss gives this error when an argument is passed: __init__() takes 1 positional argument but 2 were given
這是我用於不平衡數據的代碼,用於對數據集進行欠采樣。
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
不取位置 arguments,只取關鍵字 arguments。
ns = NearMiss(sampling_strategy=0.8)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.