当前位置:网站首页>什么是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
边栏推荐
- Global and Chinese market of lighting control components 2022-2028: Research Report on technology, participants, trends, market size and share
- Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
- [opengl] bone animation blending effect
- Tonybot humanoid robot checks the port and corresponds to port 0701
- 7-1 positive integer a+b (15 points)
- 406. Reconstruct the queue according to height
- 7-3 rental (20 points)
- How does vs+qt set the software version copyright, obtain the software version and display the version number?
- 4-24--4-28
- Address book sorting
猜你喜欢

Byte practice plane longitude 2

PS tips - draw green earth with a brush

C language fcntl function

C # realizes the login interface, and the password asterisk is displayed (hide the input password)

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03

Yolov5 series (I) -- network visualization tool netron

QT program font becomes larger on computers with different resolutions, overflowing controls

表单文本框的使用(一) 选择文本

Detailed explanation of four modes of distributed transaction (Seata)

Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
随机推荐
Implement Gobang with C language
NOI OPENJUDGE 1.4(15)
Zzuli:1042 sum of sequence 3
Composite type (custom type)
406. Reconstruct the queue according to height
Yolov5 advanced 8 format conversion between high and low versions
[ue4] geometry drawing pipeline
7-10 stack of hats (25 points) (C language solution)
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
QT program font becomes larger on computers with different resolutions, overflowing controls
Simulation of LS -al command in C language
2021-10-16 initial programming
Pytorch深度学习和目标检测实战笔记
C string format (decimal point retention / decimal conversion, etc.)
dllexport和dllimport
NOI OPENJUDGE 1.5(23)
556. The next larger element III: simple construction simulation questions
Joomla! CMS 3.0~3.4.6 RCE
. Net six design principles personal vernacular understanding, please correct if there is any error
【7.3】146. LRU caching mechanism