one-hot 编码的生成与撤销

生成one-hot 编码

from sklearn import preprocessing
import  numpy as np

enc = preprocessing.OneHotEncoder(categories='auto')
# 训练onehot编码,指定标签
enc.fit([[1],[2],[3]])

# 将标签转换成 onehot编码
result =enc.transform([[1],[3],[2]])
print(result.toarray())

撤销one-hot 编码

print(enc.inverse_transform(result.toarray()))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_38251616/article/details/129261717