[
error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.
我正设法对第一列进行编码 下面是我的代码示例:
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics for ML algorithm to be able to work with it
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()
初始化OHE类时不应传递任何obejct,只需执行以下操作:
要检查一个热编码数据的外观(请参见矩阵),只需执行以下操作:
^{pr2}$参数就是
categories
。在https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.OneHotEncoder.html
使用scikit learn版本
0.21.3
我可以获得正确的一个热编码,如下所示:正如您在警告中看到的,参数}的文档
categorical_features
将在sklearn版本0.22
之后贬值。所以,您需要使用ColumnTransformer
。Here是{相关问题 更多 >
编程相关推荐