sklearn onehot编码解读https://www.cnblogs.com/Jerry-home/p/9824085.html
- 根据训练数据统计特征每一维度的状态数(n_values_属性)
- 根据每一维度的状态数计算该特征所需位数,然后将各维度特征进行onehot编码之后拼接起来(feature_indices_则是各维特征在onehot编码中的起始索引)
from sklearn import preprocessing
feature = [['红','重','长'],['黑','轻','长'],['白','重','短'],['白','重','中']]
coder = preprocessing.OneHotEncoder()
coder.fit(feature)
x = [['白','重','短'],['白','重','中']]
coder.transform(x).toarray()
#3个特征分别占据3,2,3位
Out[16]:
array([[1., 0., 0., 0., 1., 0., 1., 0.],
[1., 0., 0., 0., 1., 1., 0., 0.]])
解读一下OneHotEncoder函数
OneHotEncoder(n_values=None,
categorical_features=None,