【发布时间】:2017-10-12 21:26:43
【问题描述】:
我正在使用来自 Kaggle 的 Titanic 数据集学习机器学习。我正在使用 sklearn 的 LabelEncoder 将文本数据转换为数字标签。以下代码适用于“Sex”,但不适用于“Embarked”。
encoder = preprocessing.LabelEncoder()
features["Sex"] = encoder.fit_transform(features["Sex"])
features["Embarked"] = encoder.fit_transform(features["Embarked"])
这是我得到的错误
Traceback (most recent call last):
File "../src/script.py", line 20, in <module>
features["Embarked"] = encoder.fit_transform(features["Embarked"])
File "/opt/conda/lib/python3.6/site-packages/sklearn/preprocessing/label.py", line 131, in fit_transform
self.classes_, y = np.unique(y, return_inverse=True)
File "/opt/conda/lib/python3.6/site-packages/numpy/lib/arraysetops.py", line 211, in unique
perm = ar.argsort(kind='mergesort' if return_index else 'quicksort')
TypeError: '>' not supported between instances of 'str' and 'float'
【问题讨论】:
标签: machine-learning scikit-learn sklearn-pandas