在scikit-learn中使用OneHotEncoder时,用作索引的数组必须为整数(或布尔值)类型

时间:2019-05-22 10:13:01

标签: python scikit-learn

我使用OneHotEncoder将分类数据更改为二进制。我用一种方法抛出一个错误,说用作索引的数组必须是整数(或布尔值)类型。我的数据集包含分类值数字值,包括浮点值。我该怎么办!

一个原始数据示例如下所示,

[0,tcp,vmnet,REJ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,275,13,0.00,0.00,1.00,1.00,0.05,0.06,0.00,255,13,0.05,0.06,0.00,0.00,0.00,0.00,1.00,1.00]
encoder = OneHotEncoder(categorical_features = nominal_cols, 
handle_unknown = "ignore")

train_x = encoder.fit_transform(train_x_raw)
test_x = encoder.transform(test_x_raw)

classifier = DecisionTreeClassifier(random_state=17)
classifier.fit(train_x, train_Y)

pred_y = classifier.predict(test_x)
  

IndexError:用作索引的数组必须为整数(或布尔值)类型

0 个答案:

没有答案