numpy TypeError:OneHotEncoder.__init__()获取了意外的关键字参数“categorical_features”

tyky79it  于 2023-08-05  发布在  Go
关注(0)|答案(1)|浏览(289)

我正在使用Jupyter Notebook使用csv文件运行这个,但这给出了一个错误,我已经尝试了这里给出的答案:TypeError: init() got an unexpected keyword argument 'categorical_features'但这没有帮助。我不知道在这里该怎么做。

# Encoding categorical data
# Encoding the Independent Variable
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X = LabelEncoder()
X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()
# Encoding the Dependent Variable
labelencoder_y = LabelEncoder()
y = labelencoder_y.fit_transform(y)

字符串
错误代码:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [22], in <cell line: 24>()
     22 labelencoder_X = LabelEncoder()
     23 X[:, 0] = labelencoder_X.fit_transform(X[:, 0])
---> 24 onehotencoder = OneHotEncoder(categorical_features = [0])
     25 X = onehotencoder.fit_transform(X).toarray()
     26 # Encoding the Dependent Variable

TypeError: OneHotEncoder.__init__() got an unexpected keyword argument 'categorical_features'

相关问题