fit_transform() 缺少 1 个必需的位置参数:'y

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

我收到以下错误;

TypeError                                 Traceback (most recent call last)
<ipython-input-109-d2877618fb0b> in <module>()
      3   if cleaned_df[column].dtype == np.number:
      4     continue
----> 5   cleaned_df[column] = LabelEncoder.fit_transform(cleaned_df[column])

TypeError: fit_transform() missing 1 required positional argument: 'y'

我的代码如下:

for column in cleaned_df.columns:
  if cleaned_df[column].dtype == np.number:
    continue
  cleaned_df[column] = LabelEncoder.fit_transform(cleaned_df[column])
logistic-regression
3个回答
3
投票

您必须在

LabelEncoder
后添加括号:

cleaned_df[column] = LabelEncoder().fit_transform(cleaned_df[column])

1
投票

LabelEncoder 后面缺少 add()。 试试这个:

le=LabelEncoder()  for column in cleaned_df.columns:  if cleaned_df[column].dtype == np.number:  continue  cleaned_df[column] = le.fit_transform(cleaned_df[column]) 


0
投票

当我们在创建 labelencoder 对象时忘记使用 () 时,就会出现此错误。

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