LabelBinarizer
import numpy as np
from sklearn.preprocessing import LabelBinarizer
lb = LabelBinarizer()
a = np.array([1,2,3,2,5,6,6])
b = lb.fit_transform(a)
print(b)
输出为:
[[1 0 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 1 0 0 0]
[0 0 0 1 0]
[0 0 0 0 1]
[0 0 0 0 1]]
LabelBinarizer
它将标签转换成了one-hot的形式。
LabelEncoder
import numpy as np
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
a = np.array([1,2,3,2,5,6,6])
e = le.fit_transform(a)
print(e)
输出为:
[0 1 2 1 3 4 4]
LabelEncoder()
对标签进行了编码,转换成了对应数值。
网友评论