【发布时间】:2019-02-08 15:52:38
【问题描述】:
我有一个数据集,其中包含以下分类数据colname。 使用 sklearn 执行 one_hot_encoding 时出现错误。
def ohe_encode(train, test, index):
Onehot = OneHotEncoder(categorical_features='all', handle_unknown='error')
x_train_1 = train
x_test_1 = test
colname = df.columns[index]
Onehot.fit(train[colname].astype(str))
x_trans = Onehot.transform(train[columnns].astype(str))
new_features = Onehot.transform(test[colname].astype(str))
return (x_transform, new_features)
屏幕显示出现错误,
ValueError: could not convert string to float: 'yes'
无法找到错误原因。
提前致谢,
【问题讨论】:
-
请尝试提出更详细的标题(现已编辑)。
标签: machine-learning scikit-learn