【发布时间】:2018-10-31 19:45:51
【问题描述】:
我在 numpy 数组上应用 OneHotEncoder。
这是代码
print X.shape, test_data.shape #gives 4100, 15) (410, 15)
onehotencoder_1 = OneHotEncoder(categorical_features = [0, 3, 4, 5, 6, 8, 9, 11, 12])
X = onehotencoder_1.fit_transform(X).toarray()
onehotencoder_2 = OneHotEncoder(categorical_features = [0, 3, 4, 5, 6, 8, 9, 11, 12])
test_data = onehotencoder_2.fit_transform(test_data).toarray()
print X.shape, test_data.shape #gives (4100, 46) (410, 43)
X 和 test_data 都是 <type 'numpy.ndarray'>
X 是我的训练集,test_data 是我的测试集。
为什么没有。 X 和 test_data 的列数不同。在应用 onehotencoder 后,它们应该是 46 或 43。
我正在对特定属性应用 OnehotEncoder,因为它们在 X 和 test_data 中都是分类的
有人能指出这里有什么问题吗?
【问题讨论】:
标签: python numpy scikit-learn one-hot-encoding