当前位置:网站首页>什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
2022-07-03 14:53:00 【Hali_Botebie】
什么是Label encoding
label encoding 就是用标签进行编码的意思,即将原始特征值编码为自定义的数字标签完成量化编码过程。
举例:
假如有三种颜色特征:红、黄、蓝。 在利用机器学习的算法时一般需要进行向量化或者数字化。那么你可能想令 红=1,黄=2,蓝=3. 那么这样其实实现了标签编码,即给不同类别以标签。
特点
- 优点:解决了分类编码的问题,可以自由定义量化数字。但其实也是缺点,因为数值本身没有任何含义,只是排序。如大中小编码为123,也可以编码为321,即数值没有意义。
- 缺点:可解释性比较差。比如有[dog,cat,dog,mouse,cat],我们把其转换为[1,2,1,3,2],这里就产生了一个奇怪的现象:dog和mouse的平均值是cat。因此,Label encoding编码其实并没有很宽的应用场景。
one-hot encoding ,label encoding两种编码该如何区分和使用?
1.特征数据类型
对于定类类型的数据,建议使用one-hot encoding。 定类类型就是纯分类,不排序,没有逻辑关系。比如性别分男和女,男女不存在任何逻辑关系,我们不能说男就比女好,或者相反。再者,中国各省市分类也可以用独热编码,同样各省不存在逻辑关系,这时候使用one-hot encoding会合适些。但注意,一般会舍去一个变量,比如男的对立面肯定是女,那么女就是重复信息,所以保留其中一个变量即可。
对于定序类型的数据,建议使用label encoding。 定序类型也是分类,但有排序逻辑关系,等级上高于定类。比如,学历分小学,初中,高中,本科,研究生,各个类别之间存在一定的逻辑,显然研究生学历是最高的,小学最低。这时候使用Label encoding会显得更合适,因为自定义的数字顺序可以不破坏原有逻辑,并与这个逻辑相对应。
2.所使用的模型
对数值大小敏感的模型必须使用one-hotencoding。 典型的例子就是LR和SVM。二者的损失函数对数值大小是敏感的,并且变量间的数值大小是有比较意义的。而Label encoding的数字编码没有数值大小的含义,只是一种排序,因此对于这些模型都使用one-hot encoding。
对数值大小不敏感的模型(如树模型)不建议使用one-hotencoding。 一般这类模型为树模型。如果分类类别特别多,那么one-hot encoding会分裂出很多特征变量。这时候,如果我们限制了树模型的深度而不能向下分裂的话,一些特征变量可能就因为模型无法继续分裂而被舍弃损失掉了。因此,此种情况下可以考虑使用Label encoding。
以上两点考量需要综合考虑,而非单独判断。也就是说需要结合数据类型和模型的情况来具体选择编码方式。
————————————————
版权声明:本文为CSDN博主「素笺清风」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_45834085/article/details/102991983
边栏推荐
- Yolov5 series (I) -- network visualization tool netron
- 5.2-5.3
- 4-29——4.32
- C language fcntl function
- Adc128s022 ADC Verilog design and Implementation
- On MEM series functions of C language
- Troubleshooting method of CPU surge
- QT - draw something else
- To improve efficiency or increase costs, how should developers understand pair programming?
- Plane vector addition
猜你喜欢
Analysis of gene family characteristics - chromosome location analysis
Yolov5 series (I) -- network visualization tool netron
Tonybot humanoid robot checks the port and corresponds to port 0701
[ue4] Niagara's indirect draw
C language DUP function
5.2-5.3
Use of form text box (I) select text
Qt—绘制其他东西
[graphics] adaptive shadow map
Code writing and playing method of tonybot humanoid robot at fixed distance
随机推荐
ASTC texture compression (adaptive scalable texture compression)
7-9 one way in, two ways out (25 points)
【微信小程序】WXSS 模板样式
Awvs batch operation script
Address book sorting
复合类型(自定义类型)
Class part2
Detailed explanation of four modes of distributed transaction (Seata)
Zzuli:1042 sum of sequence 3
C language DUP function
Yolov5系列(一)——网络可视化工具netron
Zzuli:1049 square sum and cubic sum
NOI OPENJUDGE 1.4(15)
Byte practice plane longitude 2
C language STR function
Tencent internship interview sorting
556. The next larger element III: simple construction simulation questions
Zzuli:1053 sine function
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%