美文网首页
LabelEncoder和LabelBinarizer的区别

LabelEncoder和LabelBinarizer的区别

作者: 一位学有余力的同学 | 来源:发表于2021-03-20 20:09 被阅读0次

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()对标签进行了编码,转换成了对应数值。

相关文章

网友评论

      本文标题:LabelEncoder和LabelBinarizer的区别

      本文链接:https://www.haomeiwen.com/subject/loawcltx.html