TypeError:__init__() 需要 2 个位置参数,但给出了 3 个 - 使用递归特征消除进行特征提取

问题描述 投票:0回答:1

我的代码给出的错误为

TypeError: __init__() takes 2 positional arguments but 3 were given.
尝试寻找额外的参数,但找不到。

尝试了之前回答的问题,但没有得到任何正确的解决方案。 我的代码如下:

features = ['EMB_CD3', 'EMB_CD45R0', 'EMB_LFA1', 'EMB_Perforin', 'EMB_Mac', 'EMB_HLA1', 'EMB_CD54', 
            'EMB_VCAM', 'Virus:1=Cox,4=B19V,6=HHV6,5=EBV,2=ADV(including double infections)', 'Viral_load_B19V-VP1_mRNA',
            'Viral_load_DNA_B19V','Virus_EBV', 'Virus_HHV-6', 'B19V-Typ1']
df_new = df[features].copy()
#KNN Imputer for missing values
imputer = KNNImputer(n_neighbors=3)
imputed = imputer.fit_transform(df_new)
df_imputed = pd.DataFrame(imputed, columns=df_new.columns)

X = df_imputed
Y = df['target'].astype(int)
#%% feature extraction using Recursive Feature Elimination
model = LogisticRegression(solver='lbfgs')
rfe = RFE(model, 10)
fit = rfe.fit(X, Y)
print("Num Features: %s" % (fit.n_features_))
print("Selected Features: %s" % (fit.support_))
print("Feature Ranking: %s" % (fit.ranking_))

编译器给出运行时错误如下:

runfile('C:/Users/drash/OneDrive/Desktop/Howto Health/preprocessing 1.py', wdir='C:/Users/drash/OneDrive/Desktop/Howto Health')
Traceback (most recent call last):
File "C:\Users\drash\OneDrive\Desktop\Howto Health\preprocessing 1.py", line 60, in <module>
    rfe = RFE(model, 10)

TypeError: __init__() takes 2 positional arguments but 3 were given
python arguments positional-argument
1个回答
0
投票

RFE 文档和构造函数信息位于此处。不要写

RFE(model, 10)
,而是尝试
RFE(model, n_features_to_select=10)

© www.soinside.com 2019 - 2024. All rights reserved.