2020-09-10
阅读量:
1538
scikit-learn 中 OneHotEncoder 参数之categorical_features
categorical_features = 'all',这个参数指定了对哪些特征进行编码,默认对所有类别都进行编码。也可以自己指定选择哪些特征,通过索引或者 bool 值来指定,看下例:
# -*- coding: utf-8 -*-from sklearn.preprocessing import OneHotEncoder enc = OneHotEncoder(categorical_features = [0,2]) # 等价于 [True, False, True]enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]]) ans = enc.transform([[0, 2, 3]]).toarray() print(ans) # 输出 [[ 1. 0. 0. 0. 0. 1. 2.]]
输出结果中前两位 [1,0] 表示 0,中间四位 [0,0,0,1] 表示对第三个特征 3 编码,第二个特征 2 没有进行编码,就放在最后一位。






评论(0)


暂无数据
推荐帖子
0条评论
0条评论