【发布时间】:2018-10-23 08:51:23
【问题描述】:
我正在构建一个随机森林模型,我的训练数据集中有 3 个分类变量。 sklearn RandomForest 不允许模型中的分类变量
我使用 Labelencoder() 在训练集上使用 fit_transform 将这些变量转换为数值变量,但是在测试集上运行转换时出现错误
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
X_train.apply(le.fit_transform)
X_test.apply(le.transform)
我收到以下错误消息:
ValueError: ("y contains new labels: ['female' 'male']", '发生在索引 Sex')
【问题讨论】:
-
请提供minimal reproducible example,以便有人知道如何重现您的问题并确定解决方案。
标签: python scikit-learn