LableEncoder编码

from sklearn.preprocessing import LabelEncoder
#举例对属性job进行LE编码
LE = LabelEncoder()
label = LE.fit_transform(train['job'])
print(label)
sorted_job = sorted(train['job'].value_counts().keys())
for i in range(12):
    print(sorted_job[i],':',i)
[4 9 0 ... 1 2 4]
admin. : 0
blue-collar : 1
entrepreneur : 2
housemaid : 3
management : 4
retired : 5
self-employed : 6
services : 7
student : 8
technician : 9
unemployed : 10
unknown : 11

LabelEncoder编码是按照值的字符顺序来标号的。比如a开头的字符串对应的编码是0

posted @ 2020-10-31 20:07  从前有座山,山上  阅读(771)  评论(0编辑  收藏  举报